Mercurial > libervia-backend
comparison src/test/test_plugin_xep_0033.py @ 1057:7ea0215e7092
test: fixes the tests for plugin XEP-0033
author | souliane <souliane@mailoo.org> |
---|---|
date | Sun, 08 Jun 2014 17:39:21 +0200 |
parents | c37a24922f27 |
children | 2308f8405ffb |
comparison
equal
deleted
inserted
replaced
1056:a5cfa9bb4541 | 1057:7ea0215e7092 |
---|---|
21 """ Plugin extended addressing stanzas """ | 21 """ Plugin extended addressing stanzas """ |
22 | 22 |
23 from constants import Const | 23 from constants import Const |
24 from sat.test import helpers | 24 from sat.test import helpers |
25 from sat.plugins import plugin_xep_0033 as plugin | 25 from sat.plugins import plugin_xep_0033 as plugin |
26 from sat.core.sat_main import AbortSendMessage, MessageSentAndStored | 26 from sat.core.exceptions import CancelError |
27 from sat.core.log import getLogger | 27 from sat.core.log import getLogger |
28 from copy import deepcopy | 28 from copy import deepcopy |
29 from twisted.internet import defer | 29 from twisted.internet import defer |
30 from wokkel.generic import parseXml | 30 from wokkel.generic import parseXml |
31 from twisted.words.protocols.jabber.jid import JID | 31 from twisted.words.protocols.jabber.jid import JID |
101 | 101 |
102 def sendMessageErrback(failure, exception_class): | 102 def sendMessageErrback(failure, exception_class): |
103 """If the failure does encapsulate the expected exception, it will be silently | 103 """If the failure does encapsulate the expected exception, it will be silently |
104 trapped, otherwise it will be re-raised and will make the test fail""" | 104 trapped, otherwise it will be re-raised and will make the test fail""" |
105 failure.trap(exception_class) | 105 failure.trap(exception_class) |
106 if exception_class == MessageSentAndStored: | |
107 assertAddresses(failure.value.mess_data) | |
108 | 106 |
109 def checkSentAndStored(): | 107 def checkSentAndStored(): |
110 """Check that all the recipients got their messages and that the history has been filled. | 108 """Check that all the recipients got their messages and that the history has been filled. |
111 /!\ see the comments in XEP_0033.sendAndStoreMessage""" | 109 /!\ see the comments in XEP_0033.sendAndStoreMessage""" |
112 sent = [] | 110 sent = [] |
135 """Execute self.plugin.sendMessageTrigger with a different logging | 133 """Execute self.plugin.sendMessageTrigger with a different logging |
136 level to not pollute the output, then check that the plugin did its | 134 level to not pollute the output, then check that the plugin did its |
137 job. It should abort sending the message or add the extended | 135 job. It should abort sending the message or add the extended |
138 addressing information to the stanza. | 136 addressing information to the stanza. |
139 @param data: the data to be processed by self.plugin.sendMessageTrigger | 137 @param data: the data to be processed by self.plugin.sendMessageTrigger |
140 @param exception: AbortSendMessage or MessageSentAndStored | 138 @param exception: CancelError |
141 """ | 139 """ |
142 logger = getLogger() | 140 logger = getLogger() |
143 level = logger.getEffectiveLevel() | 141 level = logger.getEffectiveLevel() |
144 logger.setLevel(ERROR) # remove log.warning pollution | 142 logger.setLevel(ERROR) # remove log.warning pollution |
145 pre_treatments = defer.Deferred() | 143 pre_treatments = defer.Deferred() |
150 post_treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, exception)) | 148 post_treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, exception)) |
151 | 149 |
152 # feature is not supported, abort the message | 150 # feature is not supported, abort the message |
153 self.host.memory.init() | 151 self.host.memory.init() |
154 data = deepcopy(mess_data) | 152 data = deepcopy(mess_data) |
155 trigger(data, AbortSendMessage) | 153 trigger(data, CancelError) |
156 | 154 |
157 # feature is supported by the main target server | 155 # feature is supported by the main target server |
158 self.host.init() | 156 self.host.init() |
159 self.host.memory.init() | 157 self.host.memory.init() |
160 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) | 158 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) |
161 data = deepcopy(mess_data) | 159 data = deepcopy(mess_data) |
162 trigger(data, MessageSentAndStored) | 160 trigger(data, CancelError) |
163 checkSentAndStored() | 161 checkSentAndStored() |
164 | 162 |
165 # feature is supported by all target servers | 163 # feature is supported by all target servers |
166 self.host.init() | 164 self.host.init() |
167 self.host.memory.init() | 165 self.host.memory.init() |
168 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) | 166 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) |
169 for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): | 167 for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): |
170 self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE) | 168 self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE) |
171 data = deepcopy(mess_data) | 169 data = deepcopy(mess_data) |
172 trigger(data, MessageSentAndStored) | 170 trigger(data, CancelError) |
173 checkSentAndStored() | 171 checkSentAndStored() |
174 | 172 |
175 # check that a wrong recipient entity is fixed by the backend | 173 # check that a wrong recipient entity is fixed by the backend |
176 self.host.init() | 174 self.host.init() |
177 self.host.memory.init() | 175 self.host.memory.init() |
178 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) | 176 self.host.addFeature(JID(JID_STR_TO), plugin.NS_ADDRESS, PROFILE) |
179 for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): | 177 for dest in (JID_STR_X_TO, JID_STR_X_CC, JID_STR_X_BCC): |
180 self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE) | 178 self.host.addFeature(JID(JID(dest).host), plugin.NS_ADDRESS, PROFILE) |
181 data = deepcopy(mess_data) | 179 data = deepcopy(mess_data) |
182 data["to"] = JID(JID_STR_X_TO) | 180 data["to"] = JID(JID_STR_X_TO) |
183 trigger(data, MessageSentAndStored) | 181 trigger(data, CancelError) |
184 checkSentAndStored() | 182 checkSentAndStored() |