annotate tests/unit/test_plugin_xep_0167.py @ 4220:5a0bddfa34ac

plugin XEP-0234: fix action type when pre-flight file confirmation is confirmed: the `C.META_TYPE_FILE` can't be used in this case as it is a preflight and we don't have yet data such as progress ID. `C.META_TYPE_FILE` is used as a sub-type to help with dialog management in frontend.
author Goffi <goffi@goffi.org>
date Tue, 05 Mar 2024 17:31:49 +0100
parents 716dd791be46
children f1d0cde61af7
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=msid-semantic:WMS *\r\n"
4213
716dd791be46 tests (unit): fix tests
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
98 "a=ice-options:trickle\r\n"
716dd791be46 tests (unit): fix tests
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
99 "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
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"
4213
716dd791be46 tests (unit): fix tests
Goffi <goffi@goffi.org>
parents: 4071
diff changeset
102 "a=sendrecv\r\n"
4057
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 "a=rtpmap:96 opus/48000\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 "a=fmtp:96 sprop-stereo=1\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 "a=ice-ufrag:ufrag\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 "a=ice-pwd:pwd\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 "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
108 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
109
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 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
111
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 def test_parse_sdp(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 """SDP is correctly parsed to session data"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 sdp = (
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 "v=0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 "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
117 "s=-\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 "t=0 0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 "a=sendrecv\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 "a=msid-semantic:WMS *\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 "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
122 "c=IN IP4 0.0.0.0\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 "a=mid:audio\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 "a=rtpmap:96 opus/48000\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 "a=fmtp:96 sprop-stereo=1\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 "a=ice-ufrag:ufrag\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 "a=ice-pwd:pwd\r\n"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 "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
129 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
130
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 expected_session = {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 "audio": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 "application_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 "media": "audio",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 "payload_types": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 "id": 96,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 "clockrate": 48000,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 "parameters": {"sprop-stereo": "1"},
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 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 "transport_data": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 "port": 9999,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 "pwd": "pwd",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 "ufrag": "ufrag",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 "candidates": [
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 "foundation": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 "component_id": 1,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 "transport": "UDP",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 "priority": 1,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 "address": "10.0.0.1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 "port": 12345,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 "type": "host",
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 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 "id": "audio",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 "metadata": {},
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
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 assert mapping.parse_sdp(sdp) == expected_session
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
166
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 def test_build_description(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 """<description> element is generated from media data"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 session = {"metadata": {}}
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 media_data = {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 "payload_types": {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 "channels": "2",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 "clockrate": "48000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 "id": "96",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 "maxptime": "60",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 "ptime": "20",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 "parameters": {"sprop-stereo": "1"},
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 },
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 "bandwidth": "AS:40000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 "rtcp-mux": True,
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 "encryption": [
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 "tag": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 "crypto-suite": "AES_CM_128_HMAC_SHA1_80",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 "key-params": "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 "session-params": "",
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
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 description_element = mapping.build_description("audio", media_data, session)
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 # Assertions
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 assert description_element.name == "description"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 assert description_element.uri == NS_JINGLE_RTP
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 assert description_element["media"] == "audio"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
201
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 # Payload types
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 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
204 assert len(payload_types) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 assert payload_types[0].name == "payload-type"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 assert payload_types[0]["id"] == "96"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 assert payload_types[0]["channels"] == "2"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 assert payload_types[0]["clockrate"] == "48000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 assert payload_types[0]["maxptime"] == "60"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 assert payload_types[0]["name"] == "opus"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 assert payload_types[0]["ptime"] == "20"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
212
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 # Parameters
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 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
215 assert len(parameters) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 assert parameters[0].name == "parameter"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 assert parameters[0]["name"] == "sprop-stereo"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 assert parameters[0]["value"] == "1"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
219
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 # Bandwidth
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 bandwidth = list(description_element.elements(NS_JINGLE_RTP, "bandwidth"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 assert len(bandwidth) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 assert bandwidth[0]["type"] == "AS:40000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
224
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 # RTCP-mux
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 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
227 assert len(rtcp_mux) == 1
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 # Encryption
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 encryption = list(description_element.elements(NS_JINGLE_RTP, "encryption"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 assert len(encryption) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 assert encryption[0]["required"] == "1"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 crypto = list(encryption[0].elements("crypto"))
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 assert len(crypto) == 1
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 assert crypto[0]["tag"] == "1"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 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
237 assert (
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 crypto[0]["key-params"] == "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 assert crypto[0]["session-params"] == ""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
241
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 def test_parse_description(self):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 """Parsing <description> to a dict is successful"""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 description_element = xml_tools.parse(
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 <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
247 <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
248 <parameter name="sprop-stereo" value="1" />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 </payload-type>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 <bandwidth type="AS:40000" />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 <rtcp-mux />
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 <encryption required="1">
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 <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
254 </encryption>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 </description>
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
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 parsed_data = mapping.parse_description(description_element)
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 # Assertions
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 assert parsed_data["payload_types"] == {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 96: {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 "channels": "2",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 "clockrate": "48000",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 "maxptime": "60",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 "name": "opus",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 "ptime": "20",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 "parameters": {"sprop-stereo": "1"},
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 }
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 assert parsed_data["bandwidth"] == "AS:40000"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 assert parsed_data["rtcp-mux"] is True
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 assert parsed_data["encryption_required"] is True
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 assert parsed_data["encryption"] == [
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 {
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 "tag": "1",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 "crypto-suite": "AES_CM_128_HMAC_SHA1_80",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 "key-params": "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 "session-params": "",
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
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 class TestXEP0167:
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 def test_jingle_session_info(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 """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
288 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 session = {"id": "123"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 mock_call_info = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 host.bridge.call_info = mock_call_info
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
292
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 jingle_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 <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
300 </jingle>
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
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 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
305
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 mock_call_info.assert_called_with(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 session["id"],
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 "mute",
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 data_format.serialise({"name": "mute_name"}),
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 client.profile,
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
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 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
314 """When receiving invalid actions, no further action is taken."""
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 session = {"id": "123"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 mock_call_info = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 host.bridge.call_info = mock_call_info
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
319
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 jingle_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 <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
327 </jingle>
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
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 xep_0167.jingle_session_info(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 client, "invalid", session, "content_name", jingle_elt
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 mock_call_info.assert_not_called()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
335
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 def test_send_info(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 """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
338 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 session_id = "123"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 extra = {"name": "test"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
341
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 iq_elt = xml_tools.parse(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 """
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 <iq from='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 id='yh3gr714'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 to='client2@example.net'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 type='set'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 <jingle xmlns='urn:xmpp:jingle:1'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 action='session-info'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 initiator='client1@example.org'
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 sid='a73sjjvkla37jfea'>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 <active xmlns='urn:xmpp:jingle:apps:rtp:info:1'/>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 </jingle>
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 </iq>
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 )
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 jingle_elt = iq_elt.firstChildElement()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 mock_send = MagicMock()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 iq_elt.send = mock_send
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 with patch.object(
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 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
363 ):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 xep_0167.send_info(client, session_id, "mute", extra)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
365
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 info_elt = jingle_elt.firstChildElement()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 assert info_elt.name == "active"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 assert info_elt.uri == NS_JINGLE_RTP_INFO
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 mock_send.assert_called()
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
370
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 def test_send_info_invalid_actions(self, host, client):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 """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
373 xep_0167 = XEP_0167(host)
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 session_id = "123"
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 extra = {"name": "test"}
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
376
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 with raises(ValueError, match="Unkown info type 'invalid_action'"):
e807a5434f82 tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 xep_0167.send_info(client, session_id, "invalid_action", extra)