annotate src/test/test_plugin_xep_0033.py @ 1272:7fbc858cd1cd

test: fixes tests for XEP-0033
author souliane <souliane@mailoo.org>
date Fri, 19 Dec 2014 11:36:43 +0100
parents 2308f8405ffb
children 347aee3a3f5c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
1 #!/usr/bin/python
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
811
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 793
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
1fe00f0c9a91 dates update
Goffi <goffi@goffi.org>
parents: 793
diff changeset
6 # Copyright (C) 2013, 2014 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
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
23 from constants import Const
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
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
27 from sat.core.log import getLogger
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
28 from copy import deepcopy
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
29 from twisted.internet import defer
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
30 from wokkel.generic import parseXml
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
31 from twisted.words.protocols.jabber.jid import JID
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
32 from logging import ERROR
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
33
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
34 PROFILE_INDEX = 0
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
35 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
36 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
37 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
38 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
39 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
40 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
41
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
42 ADDRS = ('to', JID_STR_X_TO, 'cc', JID_STR_X_CC, 'bcc', JID_STR_X_BCC)
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
43
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
44
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
45 class XEP_0033Test(helpers.SatTestCase):
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 setUp(self):
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
48 self.host = helpers.FakeSAT()
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
49 self.plugin = plugin.XEP_0033(self.host)
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
50
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
51 def test_messageReceived(self):
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
52 self.host.memory.reinit()
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
53 xml = u"""
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
54 <message type="chat" from="%s" to="%s" id="test_1">
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
55 <body>test</body>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
56 <addresses xmlns='http://jabber.org/protocol/address'>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
57 <address type='to' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
58 <address type='cc' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
59 <address type='bcc' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
60 </addresses>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
61 </message>
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
62 """ % (JID_STR_FROM, JID_STR_TO, JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
63 stanza = parseXml(xml.encode("utf-8"))
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
64 treatments = defer.Deferred()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
65 self.plugin.messageReceivedTrigger(stanza, treatments, PROFILE)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
66 data = {'extra': {}}
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
67
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
68 def cb(data):
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
69 expected = ('to', JID_STR_X_TO, 'cc', JID_STR_X_CC, 'bcc', JID_STR_X_BCC)
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
70 msg = 'Expected: %s\nGot: %s' % (expected, data['extra']['addresses'])
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
71 self.assertEqual(data['extra']['addresses'], '%s:%s\n%s:%s\n%s:%s\n' % expected, msg)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
72
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
73 treatments.addCallback(cb)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
74 treatments.callback(data)
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
75
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
76 def get_mess_data(self):
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
77 mess_data = {"to": JID(JID_STR_TO),
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
78 "type": "chat",
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
79 "message": "content",
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
80 "extra": {}
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
81 }
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
82 mess_data["extra"]["address"] = '%s:%s\n%s:%s\n%s:%s\n' % ADDRS
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
83 original_stanza = u"""
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
84 <message type="chat" from="%s" to="%s" id="test_1">
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
85 <body>content</body>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
86 </message>
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
87 """ % (JID_STR_FROM, JID_STR_TO)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
88 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
89 return mess_data
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
90
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
91 def test_sendMessageTrigger(self):
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
92 expected = self.get_mess_data()['xml']
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
93 addresses_extra = """
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
94 <addresses xmlns='http://jabber.org/protocol/address'>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
95 <address type='%s' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
96 <address type='%s' jid='%s'/>
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
97 <address type='%s' jid='%s'/>
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
98 </addresses>""" % ADDRS
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
99 addresses_element = parseXml(addresses_extra.encode('utf-8'))
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
100 expected.addChild(addresses_element)
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
101
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
102 def assertAddresses(mess_data):
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
103 """The mess_data that we got here has been modified by self.plugin.sendMessageTrigger,
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
104 check that the addresses element has been added to the stanza."""
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
105 self.assertEqualXML(mess_data['xml'].toXml().encode("utf-8"), expected.toXml().encode("utf-8"))
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
106
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
107 def sendMessageErrback(failure, exception_class):
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
108 """If the failure does encapsulate the expected exception, it will be silently
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
109 trapped, otherwise it will be re-raised and will make the test fail"""
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
110 failure.trap(exception_class)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
111
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
112 def checkSentAndStored():
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
113 """Check that all the recipients got their messages and that the history has been filled.
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
114 /!\ see the comments in XEP_0033.sendAndStoreMessage"""
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
115 sent = []
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
116 stored = []
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
117 d_list = []
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
118
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
119 def cb(entities, to_jid, logger, level):
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
120 if host in entities:
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
121 if host not in sent: # send the message to the entity offering the feature
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
122 sent.append(host)
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
123 stored.append(host)
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
124 stored.append(to_jid) # store in history for each recipient
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
125 else: # feature not supported, use normal behavior
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
126 sent.append(to_jid)
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
127 stored.append(to_jid)
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 792
diff changeset
128 logger.setLevel(level)
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
129
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
130 for to_s in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC):
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
131 to_jid = JID(to_s)
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
132 host = JID(to_jid.host)
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
133 logger = getLogger()
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
134 level = logger.getEffectiveLevel()
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
135 logger.setLevel(ERROR) # remove log.warning pollution
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
136 d = self.host.findFeaturesSet([plugin.NS_ADDRESS], jid_=host, profile_key=PROFILE)
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
137 d.addCallback(cb, to_jid, logger, level)
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
138 d_list.append(d)
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
139
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
140 def cb_list(dummy):
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
141 msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage"
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
142 sent_recipients = [JID(elt['to']) for elt in self.host.getSentMessages(PROFILE_INDEX)]
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
143 self.assertEqualUnsortedList(sent_recipients, sent, msg)
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
144 self.assertEqualUnsortedList(self.host.stored_messages, stored, msg)
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
145
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
146 return defer.DeferredList(d_list).addCallback(cb_list)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
147
924
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
148 def trigger(data, exception):
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
149 """Execute self.plugin.sendMessageTrigger with a different logging
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
150 level to not pollute the output, then check that the plugin did its
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
151 job. It should abort sending the message or add the extended
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
152 addressing information to the stanza.
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
153 @param data: the data to be processed by self.plugin.sendMessageTrigger
1057
7ea0215e7092 test: fixes the tests for plugin XEP-0033
souliane <souliane@mailoo.org>
parents: 999
diff changeset
154 @param exception: CancelError
924
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
155 """
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
156 logger = getLogger()
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 792
diff changeset
157 level = logger.getEffectiveLevel()
997
b3f383ab39da test: configuration/use of new logging system
Goffi <goffi@goffi.org>
parents: 993
diff changeset
158 logger.setLevel(ERROR) # remove log.warning pollution
924
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
159 pre_treatments = defer.Deferred()
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
160 post_treatments = defer.Deferred()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
161 self.plugin.sendMessageTrigger(data, pre_treatments, post_treatments, PROFILE)
924
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
162 post_treatments.callback(data)
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 792
diff changeset
163 logger.setLevel(level)
924
861593a5652b test: fix tests fo plugins XEP-0033 and XEP-0085
souliane <souliane@mailoo.org>
parents: 915
diff changeset
164 post_treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, exception))
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
165 return post_treatments
793
cb2db0d85029 test: silent info/warning that were polluting the output
souliane <souliane@mailoo.org>
parents: 792
diff changeset
166
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
167 # feature is not supported, abort the message
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
168 self.host.memory.reinit()
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
169 data = self.get_mess_data()
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
170 d = trigger(data, CancelError)
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
171
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
172 # feature is supported by the main target server
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
173 self.host.reinit()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
174 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE)
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
175 data = self.get_mess_data()
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
176 d.addCallback(lambda dummy: trigger(data, CancelError))
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
177 d.addCallback(lambda dummy: checkSentAndStored())
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
178
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
179 # feature is supported by all target servers
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
180 self.host.reinit()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
181 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
182 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
183 self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
184 data = self.get_mess_data()
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
185 d.addCallback(lambda dummy: trigger(data, CancelError))
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
186 d.addCallback(lambda dummy: checkSentAndStored())
787
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
187
dd656d745d6a test: added tests for XEP-0033
souliane <souliane@mailoo.org>
parents:
diff changeset
188 # check that a wrong recipient entity is fixed by the backend
1271
2308f8405ffb test: refactoring:
souliane <souliane@mailoo.org>
parents: 1057
diff changeset
189 self.host.reinit()
999
c37a24922f27 plugin XEP_0033: fixes the server part and the tests
souliane <souliane@mailoo.org>
parents: 997
diff changeset
190 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
191 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
192 self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE)
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
193 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
194 data["to"] = JID(JID_STR_X_TO)
1272
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
195 d.addCallback(lambda dummy: trigger(data, CancelError))
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
196 d.addCallback(lambda dummy: checkSentAndStored())
7fbc858cd1cd test: fixes tests for XEP-0033
souliane <souliane@mailoo.org>
parents: 1271
diff changeset
197 return d