comparison tests/unit/test_plugin_xep_0293.py @ 4285:f1d0cde61af7

tests (unit): fix tests + black reformatting.
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2024 17:42:53 +0200
parents 4b842c1fb686
children
comparison
equal deleted inserted replaced
4284:3a550e9a2b55 4285:f1d0cde61af7
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 from twisted.words.xish import domish 19 from twisted.words.xish import domish
20 20
21 from libervia.backend.plugins.plugin_xep_0167.constants import NS_JINGLE_RTP 21 from libervia.backend.plugins.plugin_xep_0167.constants import NS_JINGLE_RTP
22 from libervia.backend.plugins.plugin_xep_0293 import NS_JINGLE_RTP_RTCP_FB, RTCP_FB_KEY, XEP_0293 22 from libervia.backend.plugins.plugin_xep_0293 import (
23 NS_JINGLE_RTP_RTCP_FB,
24 RTCP_FB_KEY,
25 XEP_0293,
26 )
23 from libervia.backend.tools import xml_tools 27 from libervia.backend.tools import xml_tools
28
24 29
25 class TestXEP0293: 30 class TestXEP0293:
26 31
27 def test_parse_sdp_rtcp_fb_general(self, host): 32 def test_parse_sdp_rtcp_fb_general(self, host):
28 """Parsing of a general RTCP feedback SDP line.""" 33 """Parsing of a general RTCP feedback SDP line."""
47 52
48 def test_parse_sdp_rtcp_fb_specific(self, host): 53 def test_parse_sdp_rtcp_fb_specific(self, host):
49 """Parsing of a payload-specific RTCP feedback SDP line.""" 54 """Parsing of a payload-specific RTCP feedback SDP line."""
50 xep_0293 = XEP_0293(host) 55 xep_0293 = XEP_0293(host)
51 56
52 application_data = { 57 application_data = {"payload_types": {96: {}}}
53 "payload_types": {96: {}}
54 }
55 transport_data = {} 58 transport_data = {}
56 59
57 # SDP line: a=rtcp-fb:96 nack 60 # SDP line: a=rtcp-fb:96 nack
58 attribute = "rtcp-fb" 61 attribute = "rtcp-fb"
59 parts = ["96", "nack"] 62 parts = ["96", "nack"]
91 94
92 def test_parse_sdp_rtcp_fb_trr_int_specific(self, host): 95 def test_parse_sdp_rtcp_fb_trr_int_specific(self, host):
93 """Parsing of a payload-specific RTCP feedback with trr-int SDP line.""" 96 """Parsing of a payload-specific RTCP feedback with trr-int SDP line."""
94 xep_0293 = XEP_0293(host) 97 xep_0293 = XEP_0293(host)
95 98
96 application_data = { 99 application_data = {"payload_types": {96: {}}}
97 "payload_types": {96: {}}
98 }
99 transport_data = {} 100 transport_data = {}
100 101
101 # SDP line: a=rtcp-fb-trr-int:96 100 102 # SDP line: a=rtcp-fb-trr-int:96 100
102 attribute = "rtcp-fb-trr-int" 103 attribute = "rtcp-fb-trr-int"
103 parts = ["96", "100"] 104 parts = ["96", "100"]
137 """Generation of SDP lines for each payload type.""" 138 """Generation of SDP lines for each payload type."""
138 xep_0293 = XEP_0293(host) 139 xep_0293 = XEP_0293(host)
139 sdp_lines = [] 140 sdp_lines = []
140 application_data = {} 141 application_data = {}
141 media_data = { 142 media_data = {
142 "payload_types": {96: {RTCP_FB_KEY: [("nack", None, {})], "rtcp-fb-trr-int": 100}} 143 "payload_types": {
144 96: {RTCP_FB_KEY: [("nack", None, {})], "rtcp-fb-trr-int": 100}
145 }
143 } 146 }
144 147
145 xep_0293._generate_sdp_content_trigger( 148 xep_0293._generate_sdp_content_trigger(
146 session={}, 149 session={},
147 local=True, 150 local=True,
202 assert payload_type_data["rtcp_fb_trr_int"][0] == 100 205 assert payload_type_data["rtcp_fb_trr_int"][0] == 100
203 206
204 def test_build_rtcp_fb_elements(self, host): 207 def test_build_rtcp_fb_elements(self, host):
205 """Building the <rtcp-fb> and <rtcp-fb-trr-int> elements.""" 208 """Building the <rtcp-fb> and <rtcp-fb-trr-int> elements."""
206 xep_0293 = XEP_0293(host) 209 xep_0293 = XEP_0293(host)
207 data = { 210 data = {RTCP_FB_KEY: [("nack", "pli", {})], "rtcp-fb-trr-int": 100}
208 RTCP_FB_KEY: [("nack", "pli", {})],
209 "rtcp-fb-trr-int": 100
210 }
211 211
212 # Test _build_description_trigger 212 # Test _build_description_trigger
213 desc_elt = domish.Element((NS_JINGLE_RTP, "description")) 213 desc_elt = domish.Element((NS_JINGLE_RTP, "description"))
214 xep_0293._build_description_trigger(desc_elt, data, {}) 214 xep_0293._build_description_trigger(desc_elt, data, {})
215 215
217 assert len(rtcp_fb_elts) == 1 217 assert len(rtcp_fb_elts) == 1
218 rtcp_fb_elt = rtcp_fb_elts[0] 218 rtcp_fb_elt = rtcp_fb_elts[0]
219 assert rtcp_fb_elt["type"] == "nack" 219 assert rtcp_fb_elt["type"] == "nack"
220 assert rtcp_fb_elt["subtype"] == "pli" 220 assert rtcp_fb_elt["subtype"] == "pli"
221 221
222 rtcp_fb_trr_int_elts = list(desc_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb-trr-int")) 222 rtcp_fb_trr_int_elts = list(
223 desc_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb-trr-int")
224 )
223 assert len(rtcp_fb_trr_int_elts) == 1 225 assert len(rtcp_fb_trr_int_elts) == 1
224 rtcp_fb_trr_int_elt = rtcp_fb_trr_int_elts[0] 226 rtcp_fb_trr_int_elt = rtcp_fb_trr_int_elts[0]
225 assert int(rtcp_fb_trr_int_elt["value"]) == 100 227 assert int(rtcp_fb_trr_int_elt["value"]) == 100
226 228
227 # Test _build_description_payload_type_trigger 229 # Test _build_description_payload_type_trigger
228 desc_elt = domish.Element((NS_JINGLE_RTP, "description")) 230 desc_elt = domish.Element((NS_JINGLE_RTP, "description"))
229 payload_type_elt = desc_elt.addElement((NS_JINGLE_RTP, "payload-type")) 231 payload_type_elt = desc_elt.addElement((NS_JINGLE_RTP, "payload-type"))
230 xep_0293._build_description_payload_type_trigger(desc_elt, {}, data, payload_type_elt) 232 xep_0293._build_description_payload_type_trigger(
233 desc_elt, {}, data, payload_type_elt
234 )
231 235
232 rtcp_fb_elts = list(payload_type_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb")) 236 rtcp_fb_elts = list(payload_type_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb"))
233 assert len(rtcp_fb_elts) == 1 237 assert len(rtcp_fb_elts) == 1
234 rtcp_fb_elt = rtcp_fb_elts[0] 238 rtcp_fb_elt = rtcp_fb_elts[0]
235 assert rtcp_fb_elt["type"] == "nack" 239 assert rtcp_fb_elt["type"] == "nack"
236 assert rtcp_fb_elt["subtype"] == "pli" 240 assert rtcp_fb_elt["subtype"] == "pli"
237 241
238 rtcp_fb_trr_int_elts = list(payload_type_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb-trr-int")) 242 rtcp_fb_trr_int_elts = list(
243 payload_type_elt.elements(NS_JINGLE_RTP_RTCP_FB, "rtcp-fb-trr-int")
244 )
239 assert len(rtcp_fb_trr_int_elts) == 1 245 assert len(rtcp_fb_trr_int_elts) == 1
240 rtcp_fb_trr_int_elt = rtcp_fb_trr_int_elts[0] 246 rtcp_fb_trr_int_elt = rtcp_fb_trr_int_elts[0]
241 assert int(rtcp_fb_trr_int_elt["value"]) == 100 247 assert int(rtcp_fb_trr_int_elt["value"]) == 100