annotate tests/unit/test_plugin_xep_0272.py @ 4320:9658c534287e

plugin XEP-0215, XEP-0376: fix bad calls to `hasFeature`: `hasFeature` was called like blocking code, missing the `await`. This has been fixed, and is now using the `memory.disco.has_feature` version.
author Goffi <goffi@goffi.org>
date Mon, 30 Sep 2024 14:14:38 +0200
parents f1d0cde61af7
children
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 @fixture
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 def xep_0272(host) -> XEP_0272:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 """Fixture for initializing XEP-0272 plugin."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 host.plugins = {
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 "XEP-0045": MagicMock(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "XEP-0166": MagicMock(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 "XEP-0167": MagicMock(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 "XEP-0249": MagicMock(),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 }
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 return XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
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 class TestXEP0272:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 def test_get_handler(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 """XEP_0272_handler is instantiated and returned."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 handler = xep_0272.get_handler(client)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 assert isinstance(handler, XEP_0272_handler)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 assert handler.plugin_parent == xep_0272
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 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
59 """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
60 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 presence_elt = domish.Element((None, "presence"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 presence_elt["from"] = TEST_ROOM_JID.full()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 muji_elt = presence_elt.addElement((NS_MUJI, "muji"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 muji_elt.addElement("preparing")
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4246
diff changeset
66 muji_data = {"preparing_jids": set()}
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4246
diff changeset
67 with patch.object(xep_0272._muc, "get_room_user_jid", return_value=TEST_ROOM_JID):
4246
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 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
69 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 xep_0272, "try_to_finish_preparation"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 ) as mock_try_to_finish_preparation:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 xep_0272.on_muji_request(presence_elt, client)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 mock_try_to_finish_preparation.assert_called_once()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
74
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 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
76 """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
77 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 presence_elt = domish.Element((None, "presence"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 presence_elt["from"] = "room@example.com/user"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 presence_elt.addElement((NS_MUJI, "muji"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
81
4285
f1d0cde61af7 tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents: 4246
diff changeset
82 muji_data = {"done_preparing": True, "preparing_jids": set(), "to_call": set()}
4246
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 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
84 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 xep_0272, "try_to_finish_preparation"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 ) as mock_try_to_finish_preparation:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 xep_0272.on_muji_request(presence_elt, client)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 mock_try_to_finish_preparation.assert_not_called()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
89
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 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
91 """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
92 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 presence_elt = domish.Element((None, "presence"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 presence_elt["from"] = "room@example.com/user"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 presence_elt.addElement((NS_MUJI, "muji"))
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
96
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 client.jid = jid.JID("room@example.com/user")
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 xep_0272, "try_to_finish_preparation"
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 ) as mock_try_to_finish_preparation:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 xep_0272.on_muji_request(presence_elt, client)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 mock_try_to_finish_preparation.assert_not_called()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
103
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 def test_try_to_finish_preparation(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 """try_to_finish_preparation sets done_preparing to True."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 room = MagicMock()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 muji_data = {"preparing_jids": set(), "to_call": set()}
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
109
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 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
111 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
112 assert muji_data["done_preparing"] is True
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
113
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 @ed
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 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
116 """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
117 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 room_jid = jid.JID("room@example.com")
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 call_data = {"sdp": "sdp_data"}
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
120
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 xep_0272,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 "generate_presence_and_muji",
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 return_value=(MagicMock(), MagicMock()),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 ):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 client, "a_send", return_value=defer.succeed(None)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 ) as mock_a_send:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 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
130 mock_a_send.assert_called()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
131
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 @ed
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 async def test_start_preparation(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 """start_preparation sends correct presence and muji data."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 room = MagicMock()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
137
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 xep_0272,
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 "generate_presence_and_muji",
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 return_value=(MagicMock(), MagicMock()),
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 ):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 with patch.object(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 client, "a_send", return_value=defer.succeed(None)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 ) as mock_a_send:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 await xep_0272.start_preparation(client, room)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 mock_a_send.assert_called()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
148
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
149
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 class TestXEP0272Handler:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 def test_connectionInitialized(self, host, client):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 """connectionInitialized adds MUJI presence observer."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 xep_0272 = XEP_0272(host)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 handler = XEP_0272_handler(xep_0272)
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 handler.parent = MagicMock()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 handler.xmlstream = MagicMock()
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 with patch.object(handler.xmlstream, "addObserver") as mock_addObserver:
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 handler.connectionInitialized()
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 mock_addObserver.assert_called_once_with(
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 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
162 )
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 def test_getDiscoInfo(self):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 """getDiscoInfo returns MUJI feature."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 handler = XEP_0272_handler(MagicMock())
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 info = handler.getDiscoInfo(MagicMock(), MagicMock())
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 assert len(info) == 1
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 assert info[0] == NS_MUJI
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 def test_getDiscoItems(self):
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 """getDiscoItems returns empty list."""
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 handler = XEP_0272_handler(MagicMock())
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 items = handler.getDiscoItems(MagicMock(), MagicMock())
5eb13251fd75 tests (unit/XEP-0272): XEP-0272 tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 assert items == []