changeset 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 (2014-03-22)
parents e77948faaef3
children 5c78cefd233f
files src/test/test_plugin_xep_0033.py src/test/test_plugin_xep_0085.py
diffstat 2 files changed, 17 insertions(+), 13 deletions(-) [+]
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()
--- a/src/test/test_plugin_xep_0085.py	Sat Mar 22 17:48:10 2014 +0100
+++ b/src/test/test_plugin_xep_0085.py	Sat Mar 22 18:47:17 2014 +0100
@@ -71,7 +71,7 @@
             expected = deepcopy(mess_data['xml'])
             expected.addElement(state, plugin.NS_CHAT_STATES)
             treatments = defer.Deferred()
-            self.plugin.sendMessageTrigger(mess_data, treatments, Const.PROFILE[0])
+            self.plugin.sendMessageTrigger(mess_data, defer.Deferred(), treatments, Const.PROFILE[0])
             xml = treatments.callbacks[0][0][0](mess_data)
             # cancel the timer to not block the process
             self.plugin.map[Const.PROFILE[0]][Const.JID[0].userhostJID()].timer.cancel()