Mercurial > libervia-backend
comparison src/test/test_plugin_xep_0033.py @ 924:861593a5652b
test: fix tests fo plugins XEP-0033 and XEP-0085
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 22 Mar 2014 18:47:17 +0100 |
parents | 6f96ee4d8cc0 |
children | e1842ebcb2f3 |
comparison
equal
deleted
inserted
replaced
923:e77948faaef3 | 924:861593a5652b |
---|---|
123 logger.setLevel(level) | 123 logger.setLevel(level) |
124 msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage" | 124 msg = "/!\ see the comments in XEP_0033.sendAndStoreMessage" |
125 self.assertEqualUnsortedList(self.host.sent_messages, sent, msg) | 125 self.assertEqualUnsortedList(self.host.sent_messages, sent, msg) |
126 self.assertEqualUnsortedList(self.host.stored_messages, stored, msg) | 126 self.assertEqualUnsortedList(self.host.stored_messages, stored, msg) |
127 | 127 |
128 def trigger(treatments, data, *args): | 128 def trigger(data, exception): |
129 """Execute self.plugin.sendMessageTrigger with a different logging | |
130 level to not pollute the output, then check that the plugin did its | |
131 job. It should abort sending the message or add the extended | |
132 addressing information to the stanza. | |
133 @param data: the data to be processed by self.plugin.sendMessageTrigger | |
134 @param exception: AbortSendMessage or MessageSentAndStored | |
135 """ | |
129 logger = logging.getLogger() | 136 logger = logging.getLogger() |
130 level = logger.getEffectiveLevel() | 137 level = logger.getEffectiveLevel() |
131 logger.setLevel(logging.ERROR) # remove warning pollution | 138 logger.setLevel(logging.ERROR) # remove warning pollution |
132 self.plugin.sendMessageTrigger(*args) | 139 pre_treatments = defer.Deferred() |
133 treatments.callback(data) | 140 post_treatments = defer.Deferred() |
141 self.plugin.sendMessageTrigger(data, pre_treatments, post_treatments, Const.PROFILE[0]) | |
142 post_treatments.callback(data) | |
134 logger.setLevel(level) | 143 logger.setLevel(level) |
144 post_treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, exception)) | |
135 | 145 |
136 # feature is not supported, abort the message | 146 # feature is not supported, abort the message |
137 self.host.memory.init() | 147 self.host.memory.init() |
138 treatments = defer.Deferred() | |
139 data = deepcopy(mess_data) | 148 data = deepcopy(mess_data) |
140 trigger(treatments, data, data, treatments, Const.PROFILE[0]) | 149 trigger(data, AbortSendMessage) |
141 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, AbortSendMessage)) | |
142 | 150 |
143 # feature is supported | 151 # feature is supported |
144 self.host.init() | 152 self.host.init() |
145 self.host.memory.init() | 153 self.host.memory.init() |
146 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0]) | 154 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0]) |
147 treatments = defer.Deferred() | |
148 data = deepcopy(mess_data) | 155 data = deepcopy(mess_data) |
149 trigger(treatments, data, data, treatments, Const.PROFILE[0]) | 156 trigger(data, MessageSentAndStored) |
150 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) | |
151 checkSentAndStored() | 157 checkSentAndStored() |
152 | 158 |
153 # check that a wrong recipient entity is fixed by the backend | 159 # check that a wrong recipient entity is fixed by the backend |
154 self.host.init() | 160 self.host.init() |
155 self.host.memory.init() | 161 self.host.memory.init() |
156 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0]) | 162 self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0]) |
157 treatments = defer.Deferred() | |
158 data = deepcopy(mess_data) | 163 data = deepcopy(mess_data) |
159 data["to"] = Const.JID[0] | 164 data["to"] = Const.JID[0] |
160 trigger(treatments, mess_data, data, treatments, Const.PROFILE[0]) | 165 trigger(data, MessageSentAndStored) |
161 treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored)) | |
162 checkSentAndStored() | 166 checkSentAndStored() |