Mercurial > libervia-backend
annotate tests/unit/test_plugin_xep_0167.py @ 4318:27bb22eace65
tests (unit/email gateway): add test for XEP-0131 handling:
rel 451
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Sep 2024 15:59:48 +0200 |
parents | 9447796408f6 |
children |
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 | 101 "a=ice-options:trickle\r\n" |
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 | 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", |
4293
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
4285
diff
changeset
|
138 "msid-semantic": "WMS", |
4057
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 "payload_types": { |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 96: { |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
141 "clockrate": 48000, |
4057
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 "id": 96, |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 "name": "opus", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 "parameters": {"sprop-stereo": "1"}, |
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 }, |
4293
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
4285
diff
changeset
|
147 "senders": "both", |
4057
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 }, |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
149 "id": "audio", |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
150 "senders": "both", |
4057
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 "transport_data": { |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
152 "candidates": [ |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
153 { |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
154 "address": "10.0.0.1", |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
155 "component_id": 1, |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
156 "foundation": "1", |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
157 "port": 12345, |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
158 "priority": 1, |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
159 "transport": "UDP", |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
160 "type": "host", |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
161 } |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
162 ], |
4057
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 "port": 9999, |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 "pwd": "pwd", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 "ufrag": "ufrag", |
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 }, |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
168 "metadata": {}, |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 } |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
171 assert mapping.parse_sdp(sdp, "responder") == expected_session |
4057
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 def test_build_description(self): |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 """<description> element is generated from media data""" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 session = {"metadata": {}} |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 media_data = { |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 "payload_types": { |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 96: { |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 "channels": "2", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 "clockrate": "48000", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 "id": "96", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 "maxptime": "60", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 "name": "opus", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 "ptime": "20", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 "parameters": {"sprop-stereo": "1"}, |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 } |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 }, |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
189 "bandwidth": "AS:40000", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 "rtcp-mux": True, |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 "encryption": [ |
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 "tag": "1", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 "crypto-suite": "AES_CM_128_HMAC_SHA1_80", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 "key-params": "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 "session-params": "", |
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 } |
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 description_element = mapping.build_description("audio", media_data, session) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 # Assertions |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 assert description_element.name == "description" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 assert description_element.uri == NS_JINGLE_RTP |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 assert description_element["media"] == "audio" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 # Payload types |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 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
|
210 assert len(payload_types) == 1 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 assert payload_types[0].name == "payload-type" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 assert payload_types[0]["id"] == "96" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 assert payload_types[0]["channels"] == "2" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 assert payload_types[0]["clockrate"] == "48000" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 assert payload_types[0]["maxptime"] == "60" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 assert payload_types[0]["name"] == "opus" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 assert payload_types[0]["ptime"] == "20" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 # Parameters |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 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
|
221 assert len(parameters) == 1 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 assert parameters[0].name == "parameter" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 assert parameters[0]["name"] == "sprop-stereo" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 assert parameters[0]["value"] == "1" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
226 # Bandwidth |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 bandwidth = list(description_element.elements(NS_JINGLE_RTP, "bandwidth")) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 assert len(bandwidth) == 1 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
229 assert bandwidth[0]["type"] == "AS:40000" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
231 # RTCP-mux |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 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
|
233 assert len(rtcp_mux) == 1 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 # Encryption |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 encryption = list(description_element.elements(NS_JINGLE_RTP, "encryption")) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 assert len(encryption) == 1 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 assert encryption[0]["required"] == "1" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 crypto = list(encryption[0].elements("crypto")) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 assert len(crypto) == 1 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 assert crypto[0]["tag"] == "1" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 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
|
243 assert ( |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 crypto[0]["key-params"] == "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx" |
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 assert crypto[0]["session-params"] == "" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 def test_parse_description(self): |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 """Parsing <description> to a dict is successful""" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 description_element = xml_tools.parse( |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 """ |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 <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
|
253 <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
|
254 <parameter name="sprop-stereo" value="1" /> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 </payload-type> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 <bandwidth type="AS:40000" /> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 <rtcp-mux /> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 <encryption required="1"> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 <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
|
260 </encryption> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 </description> |
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 ) |
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 parsed_data = mapping.parse_description(description_element) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 # Assertions |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 assert parsed_data["payload_types"] == { |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 96: { |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 "channels": "2", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 "clockrate": "48000", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 "maxptime": "60", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 "name": "opus", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 "ptime": "20", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 "parameters": {"sprop-stereo": "1"}, |
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 } |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 assert parsed_data["bandwidth"] == "AS:40000" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 assert parsed_data["rtcp-mux"] is True |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 assert parsed_data["encryption_required"] is True |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 assert parsed_data["encryption"] == [ |
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 "tag": "1", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 "crypto-suite": "AES_CM_128_HMAC_SHA1_80", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 "key-params": "inline:DPSKYRle84Ua2MjbScjadpCvFQH5Tutuls2N4/xx", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 "session-params": "", |
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 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 class TestXEP0167: |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 def test_jingle_session_info(self, host, client): |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 """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
|
294 xep_0167 = XEP_0167(host) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 session = {"id": "123"} |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 mock_call_info = MagicMock() |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 host.bridge.call_info = mock_call_info |
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_elt = xml_tools.parse( |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 """ |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 <jingle xmlns='urn:xmpp:jingle:1' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 action='session-info' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 initiator='client1@example.org' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 sid='a73sjjvkla37jfea'> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 <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
|
306 </jingle> |
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 ) |
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 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
|
311 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 mock_call_info.assert_called_with( |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 session["id"], |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 "mute", |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 data_format.serialise({"name": "mute_name"}), |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 client.profile, |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 ) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 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
|
320 """When receiving invalid actions, no further action is taken.""" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 xep_0167 = XEP_0167(host) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 session = {"id": "123"} |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 mock_call_info = MagicMock() |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 host.bridge.call_info = mock_call_info |
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_elt = xml_tools.parse( |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 """ |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 <jingle xmlns='urn:xmpp:jingle:1' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 action='session-info' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 initiator='client1@example.org' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 sid='a73sjjvkla37jfea'> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 <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
|
333 </jingle> |
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 ) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 xep_0167.jingle_session_info( |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 client, "invalid", session, "content_name", jingle_elt |
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 mock_call_info.assert_not_called() |
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 def test_send_info(self, host, client): |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
343 """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
|
344 xep_0167 = XEP_0167(host) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
345 session_id = "123" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
346 extra = {"name": "test"} |
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_elt = xml_tools.parse( |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 """ |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 <iq from='client1@example.org' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 id='yh3gr714' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 to='client2@example.net' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 type='set'> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 <jingle xmlns='urn:xmpp:jingle:1' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 action='session-info' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 initiator='client1@example.org' |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 sid='a73sjjvkla37jfea'> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 <active xmlns='urn:xmpp:jingle:apps:rtp:info:1'/> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 </jingle> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 </iq> |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
361 """ |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
362 ) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 jingle_elt = iq_elt.firstChildElement() |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 mock_send = MagicMock() |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 iq_elt.send = mock_send |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 with patch.object( |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
368 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
|
369 ): |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 xep_0167.send_info(client, session_id, "mute", extra) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
372 info_elt = jingle_elt.firstChildElement() |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
373 assert info_elt.name == "active" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
374 assert info_elt.uri == NS_JINGLE_RTP_INFO |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
375 mock_send.assert_called() |
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 def test_send_info_invalid_actions(self, host, client): |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 """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
|
379 xep_0167 = XEP_0167(host) |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 session_id = "123" |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 extra = {"name": "test"} |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 with raises(ValueError, match="Unkown info type 'invalid_action'"): |
e807a5434f82
tests (units): tests for plugin XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 xep_0167.send_info(client, session_id, "invalid_action", extra) |