diff 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
line wrap: on
line diff
--- a/src/test/test_plugin_xep_0033.py	Sat Mar 22 17:48:10 2014 +0100
+++ b/src/test/test_plugin_xep_0033.py	Sat Mar 22 18:47:17 2014 +0100
@@ -125,38 +125,42 @@
             self.assertEqualUnsortedList(self.host.sent_messages, sent, msg)
             self.assertEqualUnsortedList(self.host.stored_messages, stored, msg)
 
-        def trigger(treatments, data, *args):
+        def trigger(data, exception):
+            """Execute self.plugin.sendMessageTrigger with a different logging
+            level to not pollute the output, then check that the plugin did its
+            job. It should abort sending the message or add the extended
+            addressing information to the stanza.
+            @param data: the data to be processed by self.plugin.sendMessageTrigger
+            @param exception: AbortSendMessage or MessageSentAndStored
+            """
             logger = logging.getLogger()
             level = logger.getEffectiveLevel()
             logger.setLevel(logging.ERROR)  # remove warning pollution
-            self.plugin.sendMessageTrigger(*args)
-            treatments.callback(data)
+            pre_treatments = defer.Deferred()
+            post_treatments = defer.Deferred()
+            self.plugin.sendMessageTrigger(data, pre_treatments, post_treatments, Const.PROFILE[0])
+            post_treatments.callback(data)
             logger.setLevel(level)
+            post_treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, exception))
 
         # feature is not supported, abort the message
         self.host.memory.init()
-        treatments = defer.Deferred()
         data = deepcopy(mess_data)
-        trigger(treatments, data, data, treatments, Const.PROFILE[0])
-        treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, AbortSendMessage))
+        trigger(data, AbortSendMessage)
 
         # feature is supported
         self.host.init()
         self.host.memory.init()
         self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0])
-        treatments = defer.Deferred()
         data = deepcopy(mess_data)
-        trigger(treatments, data, data, treatments, Const.PROFILE[0])
-        treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored))
+        trigger(data, MessageSentAndStored)
         checkSentAndStored()
 
         # check that a wrong recipient entity is fixed by the backend
         self.host.init()
         self.host.memory.init()
         self.host.memory.addServerFeature(plugin.NS_ADDRESS, self.host.getClientHostJid(Const.PROFILE[0]), Const.PROFILE[0])
-        treatments = defer.Deferred()
         data = deepcopy(mess_data)
         data["to"] = Const.JID[0]
-        trigger(treatments, mess_data, data, treatments, Const.PROFILE[0])
-        treatments.addCallbacks(assertAddresses, lambda failure: sendMessageErrback(failure, MessageSentAndStored))
+        trigger(data, MessageSentAndStored)
         checkSentAndStored()