annotate sat/test/test_plugin_xep_0033.py @ 3857:7d11e42b150e

cli (blog/set): show ID of published item
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents be6d91572633
children 524856bd7b19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
3
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
4 # SAT: a jabber client
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
6 # Copyright (C) 2013-2016 Adrien Cossa (souliane@mailoo.org)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
7
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
8 # This program is free software: you can redistribute it and/or modify
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
9 # it under the terms of the GNU Affero General Public License as published by
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
11 # (at your option) any later version.
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
12
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
13 # This program is distributed in the hope that it will be useful,
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
16 # GNU Affero General Public License for more details.
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
17
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
18 # You should have received a copy of the GNU Affero General Public License
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
20
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
21 """ Plugin extended addressing stanzas """
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
22
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
23 from .constants import Const
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
24 from sat.test import helpers
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
25 from sat.plugins import plugin_xep_0033 as plugin
1057
7ea0215e7092 test: fixes the tests for plugin XEP-0033
souliane <souliane@mailoo.org>
parents: 999
diff changeset
26 from sat.core.exceptions import CancelError
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
27 from twisted.internet import defer
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from wokkel.generic import parseXml
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from twisted.words.protocols.jabber.jid import JID
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
30
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
31 PROFILE_INDEX = 0
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
32 PROFILE = Const.PROFILE[PROFILE_INDEX]
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
33 JID_STR_FROM = Const.JID_STR[1]
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
34 JID_STR_TO = Const.PROFILE_DICT[PROFILE].host
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
35 JID_STR_X_TO = Const.JID_STR[0]
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
36 JID_STR_X_CC = Const.JID_STR[1]
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
37 JID_STR_X_BCC = Const.JID_STR[2]
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
38
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 ADDRS = ("to", JID_STR_X_TO, "cc", JID_STR_X_CC, "bcc", JID_STR_X_BCC)
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
40
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
41
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
42 class XEP_0033Test(helpers.SatTestCase):
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
43 def setUp(self):
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
44 self.host = helpers.FakeSAT()
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
45 self.plugin = plugin.XEP_0033(self.host)
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
46
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
47 def test_messageReceived(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
48 self.host.memory.reinit()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
49 xml = """
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
50 <message type="chat" from="%s" to="%s" id="test_1">
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
51 <body>test</body>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
52 <addresses xmlns='http://jabber.org/protocol/address'>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
53 <address type='to' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
54 <address type='cc' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
55 <address type='bcc' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
56 </addresses>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
57 </message>
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 """ % (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 JID_STR_FROM,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 JID_STR_TO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 JID_STR_X_TO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 JID_STR_X_CC,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 JID_STR_X_BCC,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 )
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
65 stanza = parseXml(xml.encode("utf-8"))
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
66 treatments = defer.Deferred()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 self.plugin.messageReceivedTrigger(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 self.host.getClient(PROFILE), stanza, treatments
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
69 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 data = {"extra": {}}
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
71
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 787
diff changeset
72 def cb(data):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 expected = ("to", JID_STR_X_TO, "cc", JID_STR_X_CC, "bcc", JID_STR_X_BCC)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 msg = "Expected: %s\nGot: %s" % (expected, data["extra"]["addresses"])
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
75 self.assertEqual(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 data["extra"]["addresses"], "%s:%s\n%s:%s\n%s:%s\n" % expected, msg
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 )
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
78
789
0cb423500fbb test: use the SatTestCase methods instead of builtin "assert" in tests for memory, plugin xep-0033
souliane <souliane@mailoo.org>
parents: 787
diff changeset
79 treatments.addCallback(cb)
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
80 return treatments.callback(data)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
81
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
82 def _get_mess_data(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 mess_data = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 "to": JID(JID_STR_TO),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 "type": "chat",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 "message": "content",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 "extra": {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 }
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 mess_data["extra"]["address"] = "%s:%s\n%s:%s\n%s:%s\n" % ADDRS
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
90 original_stanza = """
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
91 <message type="chat" from="%s" to="%s" id="test_1">
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
92 <body>content</body>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
93 </message>
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 """ % (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 JID_STR_FROM,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 JID_STR_TO,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 mess_data["xml"] = parseXml(original_stanza.encode("utf-8"))
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
99 return mess_data
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
100
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
101 def _assertAddresses(self, mess_data):
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
102 """The mess_data that we got here has been modified by self.plugin.messageSendTrigger,
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
103 check that the addresses element has been added to the stanza."""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 expected = self._get_mess_data()["xml"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 addresses_extra = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 """
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
107 <addresses xmlns='http://jabber.org/protocol/address'>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
108 <address type='%s' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
109 <address type='%s' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
110 <address type='%s' jid='%s'/>
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 </addresses>"""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 % ADDRS
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 addresses_element = parseXml(addresses_extra.encode("utf-8"))
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
115 expected.addChild(addresses_element)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 self.assertEqualXML(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 mess_data["xml"].toXml().encode("utf-8"), expected.toXml().encode("utf-8")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 )
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
119
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
120 def _checkSentAndStored(self):
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
121 """Check that all the recipients got their messages and that the history has been filled.
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
122 /!\ see the comments in XEP_0033.sendAndStoreMessage"""
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
123 sent = []
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
124 stored = []
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
125 d_list = []
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
126
1909
0681d69cbe0a test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
127 def cb(entities, to_jid):
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
128 if host in entities:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 host not in sent
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 ): # send the message to the entity offering the feature
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
132 sent.append(host)
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
133 stored.append(host)
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
134 stored.append(to_jid) # store in history for each recipient
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
135 else: # feature not supported, use normal behavior
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
136 sent.append(to_jid)
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
137 stored.append(to_jid)
1909
0681d69cbe0a test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
138 helpers.unmuteLogging()
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
139
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
140 for to_s in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
141 to_jid = JID(to_s)
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
142 host = JID(to_jid.host)
1909
0681d69cbe0a test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
143 helpers.muteLogging()
0681d69cbe0a test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
144 d = self.host.findFeaturesSet([plugin.NS_ADDRESS], jid_=host, profile=PROFILE)
0681d69cbe0a test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
145 d.addCallback(cb, to_jid)
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
146 d_list.append(d)
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
147
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
148 def cb_list(__):
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
149 msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 sent_recipients = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 JID(elt["to"]) for elt in self.host.getSentMessages(PROFILE_INDEX)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
152 ]
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
153 self.assertEqualUnsortedList(sent_recipients, sent, msg)
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
154 self.assertEqualUnsortedList(self.host.stored_messages, stored, msg)
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
155
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
156 return defer.DeferredList(d_list).addCallback(cb_list)
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 792
diff changeset
157
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
158 def _trigger(self, data):
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
159 """Execute self.plugin.messageSendTrigger with a different logging
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
160 level to not pollute the output, then check that the plugin did its
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
161 job. It should abort sending the message or add the extended
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
162 addressing information to the stanza.
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
163 @param data: the data to be processed by self.plugin.messageSendTrigger
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
164 """
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
165 pre_treatments = defer.Deferred()
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
166 post_treatments = defer.Deferred()
1909
0681d69cbe0a test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
167 helpers.muteLogging()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 self.plugin.messageSendTrigger(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 self.host.getClient[PROFILE], data, pre_treatments, post_treatments
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 )
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
171 post_treatments.callback(data)
1909
0681d69cbe0a test: add helpers methods muteLogging and unmuteLogging
souliane <souliane@mailoo.org>
parents: 1766
diff changeset
172 helpers.unmuteLogging()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 post_treatments.addCallbacks(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 self._assertAddresses, lambda failure: failure.trap(CancelError)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 )
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
176 return post_treatments
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
177
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
178 def test_messageSendTriggerFeatureNotSupported(self):
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
179 # feature is not supported, abort the message
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
180 self.host.memory.reinit()
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
181 data = self._get_mess_data()
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
182 return self._trigger(data)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
183
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
184 def test_messageSendTriggerFeatureSupported(self):
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
185 # feature is supported by the main target server
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
186 self.host.reinit()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
187 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
188 data = self._get_mess_data()
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
189 d = self._trigger(data)
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
190 return d.addCallback(lambda __: self._checkSentAndStored())
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
191
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
192 def test_messageSendTriggerFeatureFullySupported(self):
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
193 # feature is supported by all target servers
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
194 self.host.reinit()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
195 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
196 for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
197 self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
198 data = self._get_mess_data()
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
199 d = self._trigger(data)
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
200 return d.addCallback(lambda __: self._checkSentAndStored())
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
201
1955
633b5c21aefd backend, frontend: messages refactoring (huge commit, not finished):
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
202 def test_messageSendTriggerFixWrongEntity(self):
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
203 # check that a wrong recipient entity is fixed by the backend
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
204 self.host.reinit()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
205 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
206 for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
207 self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
208 data = self._get_mess_data()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
209 data["to"] = JID(JID_STR_X_TO)
1278
347aee3a3f5c test: fix/improve tests for plugins XEP-0033 and XEP-0085 (mainly to return a Deferred)
souliane <souliane@mailoo.org>
parents: 1272
diff changeset
210 d = self._trigger(data)
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
211 return d.addCallback(lambda __: self._checkSentAndStored())