annotate tests/unit/test_plugin_xep_0167.py @ 4180:b86912d3fd33

plugin IP: fix use of legacy URL + coroutine use: An https:/salut-a-toi.org URL was used to retrieve external IP, but it's not valid anymore, resulting in an exception. This feature is currently disabled. Also moved several methods from legacy inline callbacks to coroutines.
author Goffi <goffi@goffi.org>
date Sat, 09 Dec 2023 14:30:54 +0100
parents 4b842c1fb686
children 716dd791be46
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia: an XMPP client
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 import base64
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from unittest.mock import MagicMock, patch
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from pytest import fixture
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pytest import raises
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.words.protocols.jabber import jid
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4057
diff changeset
26 from libervia.backend.plugins.plugin_xep_0166 import XEP_0166
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4057
diff changeset
27 from libervia.backend.plugins.plugin_xep_0167 import XEP_0167, mapping
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4057
diff changeset
28 from libervia.backend.plugins.plugin_xep_0167.constants import NS_JINGLE_RTP, NS_JINGLE_RTP_INFO
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4057
diff changeset
29 from libervia.backend.tools import xml_tools
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4057
diff changeset
30 from libervia.backend.tools.common import data_format
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 @fixture(autouse=True)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 def no_application_register(monkeypatch):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 """Do not register the application in XEP-0166"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 monkeypatch.setattr(XEP_0166, "register_application", lambda *a, **kw: None)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 class TestXEP0167Mapping:
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 @fixture(scope="class", autouse=True)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def set_mapping_host(self, host):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 mapping.host = host
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def test_senders_to_sdp(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 """Senders are mapped to SDP attribute"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 assert mapping.senders_to_sdp("both", {"role": "initiator"}) == "a=sendrecv"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 assert mapping.senders_to_sdp("none", {"role": "initiator"}) == "a=inactive"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 assert mapping.senders_to_sdp("initiator", {"role": "initiator"}) == "a=sendonly"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 assert mapping.senders_to_sdp("responder", {"role": "initiator"}) == "a=recvonly"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def test_generate_sdp_from_session(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 """SDP is correctly generated from session data"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 session = {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "local_jid": jid.JID("toto@example.org/test"),
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 "metadata": {},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 "contents": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "audio": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "application_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 "media": "audio",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 "local_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "payload_types": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 "clockrate": 48000,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 "parameters": {"sprop-stereo": "1"},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 "transport_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 "local_ice_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 "ufrag": "ufrag",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 "pwd": "pwd",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 "candidates": [
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 "foundation": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 "component_id": 1,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 "transport": "UDP",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "priority": 1,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 "address": "10.0.0.1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 "port": 12345,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 "type": "host",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 ],
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 "senders": "both",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
91
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 expected_sdp = (
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 "v=0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 f"o={base64.b64encode('toto@example.org/test'.encode()).decode()} 1 1 IN IP4 0.0.0.0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 "s=-\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 "t=0 0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 "a=sendrecv\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 "a=msid-semantic:WMS *\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 "m=audio 9999 UDP/TLS/RTP/SAVPF 96\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 "c=IN IP4 0.0.0.0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 "a=mid:audio\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 "a=rtpmap:96 opus/48000\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 "a=fmtp:96 sprop-stereo=1\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 "a=ice-ufrag:ufrag\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 "a=ice-pwd:pwd\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 "a=candidate:1 1 UDP 1 10.0.0.1 12345 typ host\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 assert mapping.generate_sdp_from_session(session, True) == expected_sdp
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
110
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 def test_parse_sdp(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 """SDP is correctly parsed to session data"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 sdp = (
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 "v=0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 "o=toto@example.org/test 1 1 IN IP4 0.0.0.0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 "s=-\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 "t=0 0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 "a=sendrecv\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 "a=msid-semantic:WMS *\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 "m=audio 9999 UDP/TLS/RTP/SAVPF 96\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 "c=IN IP4 0.0.0.0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 "a=mid:audio\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 "a=rtpmap:96 opus/48000\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 "a=fmtp:96 sprop-stereo=1\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 "a=ice-ufrag:ufrag\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 "a=ice-pwd:pwd\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 "a=candidate:1 1 UDP 1 10.0.0.1 12345 typ host\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
129
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 expected_session = {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 "audio": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 "application_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 "media": "audio",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 "payload_types": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 "id": 96,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 "clockrate": 48000,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 "parameters": {"sprop-stereo": "1"},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 "transport_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 "port": 9999,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 "pwd": "pwd",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 "ufrag": "ufrag",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 "candidates": [
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 "foundation": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 "component_id": 1,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 "transport": "UDP",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 "priority": 1,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 "address": "10.0.0.1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 "port": 12345,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 "type": "host",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 ],
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 "id": "audio",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 "metadata": {},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 assert mapping.parse_sdp(sdp) == expected_session
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
165
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 def test_build_description(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 """<description> element is generated from media data"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 session = {"metadata": {}}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
169
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 media_data = {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 "payload_types": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 "channels": "2",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 "clockrate": "48000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 "id": "96",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 "maxptime": "60",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 "ptime": "20",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 "parameters": {"sprop-stereo": "1"},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 "bandwidth": "AS:40000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 "rtcp-mux": True,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 "encryption": [
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 "tag": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 "crypto-suite": "AES_CM_128_HMAC_SHA1_80",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 "key-params": "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 "session-params": "",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 ],
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
193
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 description_element = mapping.build_description("audio", media_data, session)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
195
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 # Assertions
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 assert description_element.name == "description"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 assert description_element.uri == NS_JINGLE_RTP
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 assert description_element["media"] == "audio"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
200
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 # Payload types
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 payload_types = list(description_element.elements(NS_JINGLE_RTP, "payload-type"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 assert len(payload_types) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 assert payload_types[0].name == "payload-type"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 assert payload_types[0]["id"] == "96"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 assert payload_types[0]["channels"] == "2"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 assert payload_types[0]["clockrate"] == "48000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 assert payload_types[0]["maxptime"] == "60"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 assert payload_types[0]["name"] == "opus"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 assert payload_types[0]["ptime"] == "20"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
211
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 # Parameters
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 parameters = list(payload_types[0].elements(NS_JINGLE_RTP, "parameter"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 assert len(parameters) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 assert parameters[0].name == "parameter"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 assert parameters[0]["name"] == "sprop-stereo"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 assert parameters[0]["value"] == "1"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
218
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 # Bandwidth
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 bandwidth = list(description_element.elements(NS_JINGLE_RTP, "bandwidth"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 assert len(bandwidth) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 assert bandwidth[0]["type"] == "AS:40000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
223
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 # RTCP-mux
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 rtcp_mux = list(description_element.elements(NS_JINGLE_RTP, "rtcp-mux"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 assert len(rtcp_mux) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
227
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 # Encryption
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 encryption = list(description_element.elements(NS_JINGLE_RTP, "encryption"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 assert len(encryption) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 assert encryption[0]["required"] == "1"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 crypto = list(encryption[0].elements("crypto"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 assert len(crypto) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 assert crypto[0]["tag"] == "1"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 assert crypto[0]["crypto-suite"] == "AES_CM_128_HMAC_SHA1_80"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 assert (
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 crypto[0]["key-params"] == "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 assert crypto[0]["session-params"] == ""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
240
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 def test_parse_description(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 """Parsing <description> to a dict is successful"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 description_element = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 <description xmlns="urn:xmpp:jingle:apps:rtp:1" media="audio">
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 <payload-type id="96" channels="2" clockrate="48000" maxptime="60" name="opus" ptime="20">
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 <parameter name="sprop-stereo" value="1" />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 </payload-type>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 <bandwidth type="AS:40000" />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 <rtcp-mux />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 <encryption required="1">
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 <crypto tag="1" crypto-suite="AES_CM_128_HMAC_SHA1_80" key-params="inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx" session-params="" />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 </encryption>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 </description>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
257
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 parsed_data = mapping.parse_description(description_element)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
259
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 # Assertions
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 assert parsed_data["payload_types"] == {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 "channels": "2",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 "clockrate": "48000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 "maxptime": "60",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 "ptime": "20",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 "parameters": {"sprop-stereo": "1"},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 assert parsed_data["bandwidth"] == "AS:40000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 assert parsed_data["rtcp-mux"] is True
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 assert parsed_data["encryption_required"] is True
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 assert parsed_data["encryption"] == [
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 "tag": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 "crypto-suite": "AES_CM_128_HMAC_SHA1_80",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 "key-params": "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 "session-params": "",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 ]
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
282
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
283
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 class TestXEP0167:
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 def test_jingle_session_info(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 """Bridge's call_info method is called with correct parameters."""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 session = {"id": "123"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 mock_call_info = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 host.bridge.call_info = mock_call_info
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
291
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 jingle_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 <mute xmlns="urn:xmpp:jingle:apps:rtp:info:1" name="mute_name"/>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 </jingle>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
302
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 xep_0167.jingle_session_info(client, "mute", session, "content_name", jingle_elt)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
304
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 mock_call_info.assert_called_with(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 session["id"],
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 "mute",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 data_format.serialise({"name": "mute_name"}),
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 client.profile,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
311
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 def test_jingle_session_info_invalid_actions(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 """When receiving invalid actions, no further action is taken."""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 session = {"id": "123"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 mock_call_info = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 host.bridge.call_info = mock_call_info
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
318
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 jingle_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 <invalid xmlns="urn:xmpp:jingle:apps:rtp:info:1" name="invalid_name"/>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 </jingle>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
329
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 xep_0167.jingle_session_info(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 client, "invalid", session, "content_name", jingle_elt
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 mock_call_info.assert_not_called()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
334
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 def test_send_info(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 """A jingle element with the correct info is created and sent."""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 session_id = "123"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 extra = {"name": "test"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
340
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 iq_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 <iq from='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 id='yh3gr714'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 to='client2@example.net'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 type='set'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 <active xmlns='urn:xmpp:jingle:apps:rtp:info:1'/>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 </jingle>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 </iq>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
356 jingle_elt = iq_elt.firstChildElement()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 mock_send = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 iq_elt.send = mock_send
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
359
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 with patch.object(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 xep_0167._j, "build_session_info", return_value=(iq_elt, jingle_elt)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 ):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 xep_0167.send_info(client, session_id, "mute", extra)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
364
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 info_elt = jingle_elt.firstChildElement()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 assert info_elt.name == "active"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 assert info_elt.uri == NS_JINGLE_RTP_INFO
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 mock_send.assert_called()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
369
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
370 def test_send_info_invalid_actions(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 """When trying to send invalid actions, an error is raised."""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 session_id = "123"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 extra = {"name": "test"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
375
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 with raises(ValueError, match="Unkown info type 'invalid_action'"):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 xep_0167.send_info(client, session_id, "invalid_action", extra)