annotate tests/unit/test_plugin_xep_0338.py @ 4246:5eb13251fd75

tests (unit/XEP-0272): XEP-0272 tests: fix 429
author Goffi <goffi@goffi.org>
date Wed, 15 May 2024 17:35:16 +0200
parents 716dd791be46
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4065
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia: an XMPP client
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from twisted.words.xish import domish
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4065
diff changeset
22 from libervia.backend.plugins.plugin_xep_0338 import NS_JINGLE_GROUPING, XEP_0338
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4065
diff changeset
23 from libervia.backend.tools.xml_tools import parse
4065
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
24
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 class TestXEP0338:
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 def test_parse_sdp(self, host):
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 """'group' attribute in SDP is correctly parsed"""
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 xep_0338 = XEP_0338(host)
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
30
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 call_data = {}
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 metadata = {}
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 media_type = "video"
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 application_data = {}
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 transport_data = {}
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 # SDP: a=group:BUNDLE audio video
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 attribute = "group"
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 parts = ["BUNDLE", "audio", "video"]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
40
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 xep_0338._parse_sdp_a_trigger(
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 attribute,
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 parts,
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 call_data,
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 metadata,
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 media_type,
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 application_data,
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 transport_data,
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 )
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 assert metadata == {"group": {"BUNDLE": ["audio", "video"]}}
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def test_generate_sdp(self, host):
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 """'group' attribute in SDP is correctly generated"""
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 xep_0338 = XEP_0338(host)
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
56
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 session = {"metadata": {"group": {"BUNDLE": ["audio", "video"]}}}
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 sdp_lines = []
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 local = True
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
60
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 xep_0338._generate_sdp_session_trigger(session, local, sdp_lines)
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
62
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 assert sdp_lines == ["a=group:BUNDLE audio video"]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 def test_group_building(self, host, client):
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 """<group> element are built from session in session init trigger"""
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 xep_0338 = XEP_0338(host)
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
68
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 session = {
4213
716dd791be46 tests (unit): fix tests
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
70 "contents": {"audio": {}},
4065
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 "jingle_elt": domish.Element((None, "jingle")),
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 "metadata": {"group": {"BUNDLE": ["audio", "video"]}},
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 }
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 content_name = "audio"
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 media = "audio"
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 media_data = {}
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 desc_elt = domish.Element((None, "description"))
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
78
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 xep_0338._jingle_session_init_trigger(
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 client, session, content_name, media, media_data, desc_elt
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 )
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
82
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 group_elts = list(session["jingle_elt"].elements(NS_JINGLE_GROUPING, "group"))
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 assert len(group_elts) == 1
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 group_elt = group_elts[0]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 assert group_elt["semantics"] == "BUNDLE"
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 content_names = [
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 content_elt["name"]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 for content_elt in group_elt.elements(NS_JINGLE_GROUPING, "content")
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 ]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 assert content_names == ["audio", "video"]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
92
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 def test_group_parsing(self, host, client):
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 """<group> elements are correctly parsed in jingle_handler trigger"""
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 xep_0338 = XEP_0338(host)
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
96
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 action = xep_0338._j.A_SESSION_INITIATE
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 session = {
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 "contents": ["audio", "video"],
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 "metadata": {},
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 }
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
102
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 raw_xml = """
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 <jingle xmlns='urn:xmpp:jingle:1'
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 action='session-initiate'
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 initiator='user@example.org/orchard'
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 sid='a73sjjvkla37jfea'>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 <group xmlns='urn:xmpp:jingle:apps:grouping:0' semantics='BUNDLE'>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 <content name='audio'/>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 <content name='video'/>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 </group>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 <content creator='initiator' name='audio'>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'/>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 </content>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 <content creator='initiator' name='video'>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 <description xmlns='urn:xmpp:jingle:apps:rtp:1' media='video'/>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 </content>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 </jingle>
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 """
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 session["jingle_elt"] = parse(raw_xml)
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
121
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 for content_elt in session["jingle_elt"].elements("urn:xmpp:jingle:1", "content"):
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 content_name = content_elt["name"]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 desc_elt = next(
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 content_elt.elements("urn:xmpp:jingle:apps:rtp:1", "description")
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 )
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
127
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 xep_0338._jingle_handler_trigger(
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 client, action, session, content_name, desc_elt
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 )
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
131
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 group_elts = list(session["jingle_elt"].elements(NS_JINGLE_GROUPING, "group"))
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 assert len(group_elts) == 1
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 group_elt = group_elts[0]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 assert group_elt["semantics"] == "BUNDLE"
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 content_names = [
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 content_elt["name"]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 for content_elt in group_elt.elements(NS_JINGLE_GROUPING, "content")
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 ]
34c8e7e4fa52 tests (units): tests for plugin XEP-0338:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 assert content_names == ["audio", "video"]