comparison tests/unit/test_plugin_xep_0339.py @ 4068:5241267a92b3

tests (units): tests for plugin XEP-0339: fix 439
author Goffi <goffi@goffi.org>
date Thu, 01 Jun 2023 21:37:31 +0200
parents
children 4b842c1fb686
comparison
equal deleted inserted replaced
4067:3f62c2445df1 4068:5241267a92b3
1 #!/usr/bin/env python3
2
3 # Libervia: an XMPP client
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
15
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19
20 from twisted.words.xish import domish
21
22 from sat.plugins.plugin_xep_0339 import NS_JINGLE_RTP_SSMA, XEP_0339
23 from sat.tools.xml_tools import parse
24
25
26 class TestXEP0339:
27 def test_parse_sdp(self, host):
28 """'ssrc' and 'ssrc-group' attributes in SDP are correctly parsed"""
29 xep_0339 = XEP_0339(host)
30
31 call_data = {}
32 metadata = {}
33 media_type = "video"
34 application_data = {}
35 transport_data = {}
36
37 # SDP: a=ssrc:123 label:stream_label
38 attribute = "ssrc"
39 parts = ["123", "label:stream_label"]
40
41 xep_0339._parse_sdp_a_trigger(
42 attribute,
43 parts,
44 call_data,
45 metadata,
46 media_type,
47 application_data,
48 transport_data,
49 )
50
51 assert application_data == {"ssrc": {123: {"label": "stream_label"}}}
52
53 application_data = {}
54
55 # SDP: a=ssrc-group:FID 123 456
56 attribute = "ssrc-group"
57 parts = ["FID", "123", "456"]
58
59 xep_0339._parse_sdp_a_trigger(
60 attribute,
61 parts,
62 call_data,
63 metadata,
64 media_type,
65 application_data,
66 transport_data,
67 )
68
69 assert application_data == {"ssrc-group": {"FID": [123, 456]}}
70
71 def test_generate_sdp(self, host):
72 """'ssrc' and 'ssrc-group' attributes in SDP are correctly generated"""
73 xep_0339 = XEP_0339(host)
74
75 media_data = {
76 "ssrc": {123: {"label": "stream_label"}},
77 "ssrc-group": {"FID": [123, 456]},
78 }
79 sdp_lines = []
80
81 xep_0339._generate_sdp_content_trigger(
82 {}, True, 1, {}, sdp_lines, {}, "", media_data, "video"
83 )
84
85 assert sdp_lines == ["a=ssrc:123 label:stream_label", "a=ssrc-group:FID 123 456"]
86
87 def test_parse_description(self, host):
88 """'<source>' and '<ssrc-group>' elements are correctly parsed"""
89 xep_0339 = XEP_0339(host)
90
91 media_data = {}
92 raw_xml = """
93 <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
94 <source xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' ssrc='1'>
95 <parameter name='cname' value='some_name'/>
96 <parameter name='msid' value='media'/>
97 </source>
98 <ssrc-group xmlns='urn:xmpp:jingle:apps:rtp:ssma:0' semantics='FEC'>
99 <source ssrc='2'/>
100 <source ssrc='3'/>
101 </ssrc-group>
102 </description>
103 """
104 desc_elt = parse(raw_xml)
105
106 xep_0339._parse_description_trigger(desc_elt, media_data)
107
108 assert media_data == {
109 "msid": "media",
110 "ssrc": {
111 1: {
112 "cname": "some_name",
113 "msid": "media",
114 }
115 },
116 "ssrc-group": {"FEC": [2, 3]},
117 }
118
119 def test_generate_description(self, host):
120 """'<source>' and '<ssrc-group>' elements are correctly generated"""
121 xep_0339 = XEP_0339(host)
122
123 media_data = {
124 "ssrc": {
125 1: {
126 "cname": "some_name",
127 "msid": "media",
128 }
129 },
130 "ssrc-group": {"FEC": [2, 3]},
131 }
132 session = {}
133 desc_elt = domish.Element((None, "description"))
134
135 xep_0339._build_description_trigger(desc_elt, media_data, session)
136
137 source_elts = list(desc_elt.elements(NS_JINGLE_RTP_SSMA, "source"))
138 assert len(source_elts) == 1
139 source_elt = source_elts[0]
140 assert source_elt["ssrc"] == "1"
141 param_elts = list(source_elt.elements(NS_JINGLE_RTP_SSMA, "parameter"))
142 assert len(param_elts) == 2
143 assert param_elts[0]["name"] == "cname"
144 assert param_elts[0]["value"] == "some_name"
145 assert param_elts[1]["name"] == "msid"
146 assert param_elts[1]["value"] == "media"
147
148 ssrc_group_elts = list(desc_elt.elements(NS_JINGLE_RTP_SSMA, "ssrc-group"))
149 assert len(ssrc_group_elts) == 1
150 ssrc_group_elt = ssrc_group_elts[0]
151 assert ssrc_group_elt["semantics"] == "FEC"
152 ssrc_ids = [
153 int(source_elt["ssrc"])
154 for source_elt in ssrc_group_elt.elements(NS_JINGLE_RTP_SSMA, "source")
155 ]
156 assert ssrc_ids == [2, 3]