annotate tests/unit/test_plugin_xep_0167.py @ 4285:f1d0cde61af7

tests (unit): fix tests + black reformatting.
author Goffi <goffi@goffi.org>
date Sun, 14 Jul 2024 17:42:53 +0200
parents 716dd791be46
children 9447796408f6
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
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
28 from libervia.backend.plugins.plugin_xep_0167.constants import (
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
29 NS_JINGLE_RTP,
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
30 NS_JINGLE_RTP_INFO,
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
31 )
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4057
diff changeset
32 from libervia.backend.tools import xml_tools
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4057
diff changeset
33 from libervia.backend.tools.common import data_format
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 @fixture(autouse=True)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def no_application_register(monkeypatch):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 """Do not register the application in XEP-0166"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 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
40
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 class TestXEP0167Mapping:
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 @fixture(scope="class", autouse=True)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def set_mapping_host(self, host):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 mapping.host = host
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
46
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def test_senders_to_sdp(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 """Senders are mapped to SDP attribute"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 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
50 assert mapping.senders_to_sdp("none", {"role": "initiator"}) == "a=inactive"
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
51 assert mapping.senders_to_sdp("initiator", {"role": "initiator"}) == "a=recvonly"
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
52 assert mapping.senders_to_sdp("responder", {"role": "initiator"}) == "a=sendonly"
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 def test_generate_sdp_from_session(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 """SDP is correctly generated from session data"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 session = {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 "local_jid": jid.JID("toto@example.org/test"),
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "metadata": {},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 "contents": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 "audio": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 "application_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 "media": "audio",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 "local_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 "payload_types": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 "clockrate": 48000,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 "parameters": {"sprop-stereo": "1"},
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 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 "transport_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 "local_ice_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 "ufrag": "ufrag",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 "pwd": "pwd",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 "candidates": [
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "foundation": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 "component_id": 1,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 "transport": "UDP",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 "priority": 1,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 "address": "10.0.0.1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 "port": 12345,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 "type": "host",
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 ],
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 "senders": "both",
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 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
94
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 expected_sdp = (
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 "v=0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 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
98 "s=-\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 "t=0 0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 "a=msid-semantic:WMS *\r\n"
4213
716dd791be46 tests (unit): fix tests
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
101 "a=ice-options:trickle\r\n"
716dd791be46 tests (unit): fix tests
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
102 "m=audio 9 UDP/TLS/RTP/SAVPF 96\r\n"
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 "c=IN IP4 0.0.0.0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 "a=mid:audio\r\n"
4213
716dd791be46 tests (unit): fix tests
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
105 "a=sendrecv\r\n"
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 "a=rtpmap:96 opus/48000\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 "a=fmtp:96 sprop-stereo=1\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 "a=ice-ufrag:ufrag\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 "a=ice-pwd:pwd\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 "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
111 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 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
114
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 def test_parse_sdp(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 """SDP is correctly parsed to session data"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 sdp = (
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 "v=0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 "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
120 "s=-\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 "t=0 0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 "a=sendrecv\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 "a=msid-semantic:WMS *\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 "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
125 "c=IN IP4 0.0.0.0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 "a=mid:audio\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 "a=rtpmap:96 opus/48000\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 "a=fmtp:96 sprop-stereo=1\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 "a=ice-ufrag:ufrag\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 "a=ice-pwd:pwd\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 "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
132 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
133
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 expected_session = {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 "audio": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 "application_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 "media": "audio",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 "payload_types": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 96: {
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
140 "clockrate": 48000,
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 "id": 96,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 "parameters": {"sprop-stereo": "1"},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 },
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
147 "id": "audio",
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
148 "senders": "both",
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 "transport_data": {
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
150 "candidates": [
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
151 {
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
152 "address": "10.0.0.1",
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
153 "component_id": 1,
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
154 "foundation": "1",
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
155 "port": 12345,
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
156 "priority": 1,
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
157 "transport": "UDP",
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
158 "type": "host",
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
159 }
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
160 ],
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 "port": 9999,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 "pwd": "pwd",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 "ufrag": "ufrag",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 },
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 "metadata": {},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
168
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4213
diff changeset
169 assert mapping.parse_sdp(sdp, "responder") == expected_session
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
170
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 def test_build_description(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 """<description> element is generated from media data"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 session = {"metadata": {}}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
174
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 media_data = {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 "payload_types": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 "channels": "2",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 "clockrate": "48000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 "id": "96",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 "maxptime": "60",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 "ptime": "20",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 "parameters": {"sprop-stereo": "1"},
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 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 "bandwidth": "AS:40000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 "rtcp-mux": True,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 "encryption": [
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 "tag": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 "crypto-suite": "AES_CM_128_HMAC_SHA1_80",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 "key-params": "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 "session-params": "",
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 ],
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 description_element = mapping.build_description("audio", media_data, session)
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 # Assertions
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 assert description_element.name == "description"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 assert description_element.uri == NS_JINGLE_RTP
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 assert description_element["media"] == "audio"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
205
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 # Payload types
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 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
208 assert len(payload_types) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 assert payload_types[0].name == "payload-type"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 assert payload_types[0]["id"] == "96"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 assert payload_types[0]["channels"] == "2"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 assert payload_types[0]["clockrate"] == "48000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 assert payload_types[0]["maxptime"] == "60"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 assert payload_types[0]["name"] == "opus"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 assert payload_types[0]["ptime"] == "20"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
216
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 # Parameters
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 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
219 assert len(parameters) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 assert parameters[0].name == "parameter"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 assert parameters[0]["name"] == "sprop-stereo"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 assert parameters[0]["value"] == "1"
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 # Bandwidth
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 bandwidth = list(description_element.elements(NS_JINGLE_RTP, "bandwidth"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 assert len(bandwidth) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 assert bandwidth[0]["type"] == "AS:40000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
228
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 # RTCP-mux
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 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
231 assert len(rtcp_mux) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
232
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 # Encryption
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 encryption = list(description_element.elements(NS_JINGLE_RTP, "encryption"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 assert len(encryption) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 assert encryption[0]["required"] == "1"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 crypto = list(encryption[0].elements("crypto"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 assert len(crypto) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 assert crypto[0]["tag"] == "1"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 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
241 assert (
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 crypto[0]["key-params"] == "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 assert crypto[0]["session-params"] == ""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
245
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 def test_parse_description(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 """Parsing <description> to a dict is successful"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 description_element = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 <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
251 <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
252 <parameter name="sprop-stereo" value="1" />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 </payload-type>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 <bandwidth type="AS:40000" />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 <rtcp-mux />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 <encryption required="1">
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 <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
258 </encryption>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 </description>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
262
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 parsed_data = mapping.parse_description(description_element)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
264
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 # Assertions
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 assert parsed_data["payload_types"] == {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 "channels": "2",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 "clockrate": "48000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 "maxptime": "60",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 "ptime": "20",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 "parameters": {"sprop-stereo": "1"},
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 }
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 assert parsed_data["bandwidth"] == "AS:40000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 assert parsed_data["rtcp-mux"] is True
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 assert parsed_data["encryption_required"] is True
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 assert parsed_data["encryption"] == [
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 "tag": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 "crypto-suite": "AES_CM_128_HMAC_SHA1_80",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 "key-params": "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 "session-params": "",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 ]
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
287
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
288
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 class TestXEP0167:
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 def test_jingle_session_info(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 """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
292 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 session = {"id": "123"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 mock_call_info = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 host.bridge.call_info = mock_call_info
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
296
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 jingle_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 <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
304 </jingle>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
307
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 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
309
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 mock_call_info.assert_called_with(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 session["id"],
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 "mute",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 data_format.serialise({"name": "mute_name"}),
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 client.profile,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
316
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 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
318 """When receiving invalid actions, no further action is taken."""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 session = {"id": "123"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 mock_call_info = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 host.bridge.call_info = mock_call_info
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
323
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 jingle_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 <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
331 </jingle>
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 )
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 xep_0167.jingle_session_info(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 client, "invalid", session, "content_name", jingle_elt
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 mock_call_info.assert_not_called()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
339
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 def test_send_info(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 """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
342 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 session_id = "123"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 extra = {"name": "test"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
345
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 iq_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 <iq from='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 id='yh3gr714'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 to='client2@example.net'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 type='set'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
356 <active xmlns='urn:xmpp:jingle:apps:rtp:info:1'/>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 </jingle>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 </iq>
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 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 jingle_elt = iq_elt.firstChildElement()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 mock_send = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 iq_elt.send = mock_send
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 with patch.object(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 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
367 ):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 xep_0167.send_info(client, session_id, "mute", extra)
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 info_elt = jingle_elt.firstChildElement()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 assert info_elt.name == "active"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 assert info_elt.uri == NS_JINGLE_RTP_INFO
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 mock_send.assert_called()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
374
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 def test_send_info_invalid_actions(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 """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
377 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 session_id = "123"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 extra = {"name": "test"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
380
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 with raises(ValueError, match="Unkown info type 'invalid_action'"):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 xep_0167.send_info(client, session_id, "invalid_action", extra)