annotate tests/unit/test_plugin_xep_0272.py @ 4279:6276242736c3

doc (components): Documentation for the new `Conferences` component: fix 445
author Goffi <goffi@goffi.org>
date Fri, 05 Jul 2024 17:18:37 +0200
parents 5eb13251fd75
children f1d0cde61af7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4246
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia: an XMPP client
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2024 Jérôme Poisson (goffi@goffi.org)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from unittest.mock import MagicMock, patch
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from pytest_twisted import ensureDeferred as ed
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from pytest import fixture
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from twisted.internet import defer
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from twisted.words.protocols.jabber import jid
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.xish import domish
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from libervia.backend.plugins.plugin_xep_0272 import (
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 NS_MUJI,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 PRESENCE_MUJI,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 XEP_0272,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 XEP_0272_handler,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 )
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from libervia.backend.tools.common import data_format
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 TEST_ROOM_JID = jid.JID("room@example.com/user")
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
38
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 @fixture
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 def xep_0272(host) -> XEP_0272:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 """Fixture for initializing XEP-0272 plugin."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 host.plugins = {
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "XEP-0045": MagicMock(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 "XEP-0166": MagicMock(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 "XEP-0167": MagicMock(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 "XEP-0249": MagicMock(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 }
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 return XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
49
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
50
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class TestXEP0272:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 def test_get_handler(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 """XEP_0272_handler is instantiated and returned."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 handler = xep_0272.get_handler(client)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 assert isinstance(handler, XEP_0272_handler)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 assert handler.plugin_parent == xep_0272
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
58
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def test_on_muji_request_preparing_state(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 """try_to_finish_preparation is called when preparing_state is True."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 presence_elt = domish.Element((None, "presence"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 presence_elt["from"] = TEST_ROOM_JID.full()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 muji_elt = presence_elt.addElement((NS_MUJI, "muji"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 muji_elt.addElement("preparing")
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
66
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 muji_data = {
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 "preparing_jids": set()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 }
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 xep_0272._muc, "get_room_user_jid", return_value=TEST_ROOM_JID) :
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 with patch.object(xep_0272, "get_muji_data", return_value=muji_data):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 xep_0272, "try_to_finish_preparation"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 ) as mock_try_to_finish_preparation:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 xep_0272.on_muji_request(presence_elt, client)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 mock_try_to_finish_preparation.assert_called_once()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
78
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 def test_on_muji_request_not_preparing_state(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 """try_to_finish_preparation is not called when preparing_state is False."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 presence_elt = domish.Element((None, "presence"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 presence_elt["from"] = "room@example.com/user"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 presence_elt.addElement((NS_MUJI, "muji"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
85
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 muji_data = {
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 "done_preparing": True,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 "preparing_jids": set(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 "to_call": set()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 }
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 with patch.object(xep_0272, "get_muji_data", return_value=muji_data):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 xep_0272, "try_to_finish_preparation"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 ) as mock_try_to_finish_preparation:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 xep_0272.on_muji_request(presence_elt, client)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 mock_try_to_finish_preparation.assert_not_called()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
97
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 def test_on_muji_request_own_jid(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 """try_to_finish_preparation is not called when the presence is from own JID."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 presence_elt = domish.Element((None, "presence"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 presence_elt["from"] = "room@example.com/user"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 presence_elt.addElement((NS_MUJI, "muji"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
104
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 client.jid = jid.JID("room@example.com/user")
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 xep_0272, "try_to_finish_preparation"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 ) as mock_try_to_finish_preparation:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 xep_0272.on_muji_request(presence_elt, client)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 mock_try_to_finish_preparation.assert_not_called()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
111
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 def test_try_to_finish_preparation(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 """try_to_finish_preparation sets done_preparing to True."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 room = MagicMock()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 muji_data = {"preparing_jids": set(), "to_call": set()}
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 with patch.object(xep_0272, "get_muji_data", return_value=muji_data):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 xep_0272.try_to_finish_preparation(client, room, muji_data)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 assert muji_data["done_preparing"] is True
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
121
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 @ed
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 async def test_call_group_data_set(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 """call_group_data_set sends correct presence and muji data."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 room_jid = jid.JID("room@example.com")
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 call_data = {"sdp": "sdp_data"}
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
128
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 xep_0272,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 "generate_presence_and_muji",
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 return_value=(MagicMock(), MagicMock()),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 ):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 client, "a_send", return_value=defer.succeed(None)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 ) as mock_a_send:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 await xep_0272.call_group_data_set(client, room_jid, call_data)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 mock_a_send.assert_called()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
139
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 @ed
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 async def test_start_preparation(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 """start_preparation sends correct presence and muji data."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 room = MagicMock()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
145
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 xep_0272,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 "generate_presence_and_muji",
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 return_value=(MagicMock(), MagicMock()),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 ):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 client, "a_send", return_value=defer.succeed(None)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 ) as mock_a_send:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 await xep_0272.start_preparation(client, room)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 mock_a_send.assert_called()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
156
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
157
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 class TestXEP0272Handler:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 def test_connectionInitialized(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 """connectionInitialized adds MUJI presence observer."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 handler = XEP_0272_handler(xep_0272)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 handler.parent = MagicMock()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 handler.xmlstream = MagicMock()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
165
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 with patch.object(handler.xmlstream, "addObserver") as mock_addObserver:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 handler.connectionInitialized()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 mock_addObserver.assert_called_once_with(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 PRESENCE_MUJI, xep_0272.on_muji_request, client=handler.parent
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 )
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
171
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 def test_getDiscoInfo(self):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 """getDiscoInfo returns MUJI feature."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 handler = XEP_0272_handler(MagicMock())
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 info = handler.getDiscoInfo(MagicMock(), MagicMock())
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 assert len(info) == 1
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 assert info[0] == NS_MUJI
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
178
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 def test_getDiscoItems(self):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 """getDiscoItems returns empty list."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 handler = XEP_0272_handler(MagicMock())
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 items = handler.getDiscoItems(MagicMock(), MagicMock())
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 assert items == []