88import pytest
99
1010from tests import load_fixture
11- from webrtc_models import RTCConfiguration , RTCIceCandidate , RTCIceServer
11+ from webrtc_models import (
12+ RTCConfiguration ,
13+ RTCIceCandidate ,
14+ RTCIceCandidateInit ,
15+ RTCIceServer ,
16+ )
1217
1318if TYPE_CHECKING :
1419 from mashumaro .mixins .orjson import DataClassORJSONMixin
2732 (RTCConfiguration , "RTCConfiguration_empty.json" ),
2833 (RTCConfiguration , "RTCConfiguration_one_iceServer.json" ),
2934 (RTCConfiguration , "RTCConfiguration_multiple_iceServers.json" ),
30- # RTCIceCandidate
31- (RTCIceCandidate , "RTCIceCandidate_end .json" ),
32- (RTCIceCandidate , "RTCIceCandidate_candidate .json" ),
35+ # RTCIceCandidateInit
36+ (RTCIceCandidateInit , "RTCIceCandidateInit_end .json" ),
37+ (RTCIceCandidateInit , "RTCIceCandidateInit_candidate .json" ),
3338 ],
3439)
3540def test_decoding_and_encoding (
@@ -51,3 +56,50 @@ def test_decoding_and_encoding(
5156 # Verify dict
5257 assert instance_dict == file_content_dict
5358 assert instance == clazz .from_dict (instance_dict )
59+
60+
61+ @pytest .mark .parametrize (
62+ ("clazz" , "filename" ),
63+ [
64+ # RTCIceCandidate
65+ (RTCIceCandidate , "RTCIceCandidate_end.json" ),
66+ (RTCIceCandidate , "RTCIceCandidate_candidate.json" ),
67+ ],
68+ )
69+ def test_decoding_and_encoding_deprecated (
70+ snapshot : SnapshotAssertion ,
71+ clazz : type [DataClassORJSONMixin ],
72+ filename : str ,
73+ ) -> None :
74+ """Test decoding/encoding."""
75+ file_content = load_fixture (filename )
76+ with pytest .deprecated_call ():
77+ instance = clazz .from_json (file_content )
78+ assert instance == snapshot (name = "dataclass" )
79+
80+ file_content_dict = orjson .loads (file_content )
81+ instance_dict = instance .to_dict ()
82+
83+ # Verify json
84+ assert instance .to_json () == orjson .dumps (file_content_dict ).decode ()
85+
86+ # Verify dict
87+ assert instance_dict == file_content_dict
88+ with pytest .deprecated_call ():
89+ assert instance == clazz .from_dict (instance_dict )
90+
91+
92+ def test_no_mid_and_mlineindex () -> None :
93+ """Test spd_mid and sdp_multilineindex raises TypeError."""
94+ file_content = load_fixture ("RTCIceCandidate_candidate.json" )
95+ cand = RTCIceCandidateInit .from_json (file_content )
96+ assert cand .sdp_m_line_index == 0
97+ assert cand .sdp_mid is None
98+
99+
100+ def test_invalid_mlineindex () -> None :
101+ """Test spd_mid and sdp_multilineindex raises TypeError."""
102+ file_content = load_fixture ("RTCIceCandidateInit_invalid.json" )
103+ msg = "sdpMLineIndex must be greater than or equal to 0"
104+ with pytest .raises (ValueError , match = msg ):
105+ RTCIceCandidateInit .from_json (file_content )
0 commit comments