summaryrefslogtreecommitdiff
path: root/tests/test_stream_handlers.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2011-11-19 18:43:38 -0800
committerLance Stout <lancestout@gmail.com>2011-11-19 18:43:38 -0800
commitf9d0b55ca3c3f43a3bc87047f55cbf4e16c3b67b (patch)
tree59accbb0ae2efe10560c31255a2cfca04f1baf7a /tests/test_stream_handlers.py
parentb54cc97e4c1c4c6927962f4f9d5ce581b31b5408 (diff)
downloadslixmpp-f9d0b55ca3c3f43a3bc87047f55cbf4e16c3b67b.tar.gz
slixmpp-f9d0b55ca3c3f43a3bc87047f55cbf4e16c3b67b.tar.bz2
slixmpp-f9d0b55ca3c3f43a3bc87047f55cbf4e16c3b67b.tar.xz
slixmpp-f9d0b55ca3c3f43a3bc87047f55cbf4e16c3b67b.zip
Add unit test for copying stanzas when passed to events.
Diffstat (limited to 'tests/test_stream_handlers.py')
-rw-r--r--tests/test_stream_handlers.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test_stream_handlers.py b/tests/test_stream_handlers.py
index 1b831e21..6f3ea67b 100644
--- a/tests/test_stream_handlers.py
+++ b/tests/test_stream_handlers.py
@@ -1,5 +1,6 @@
import time
+from sleekxmpp import Message
from sleekxmpp.test import *
from sleekxmpp.xmlstream.handler import *
from sleekxmpp.xmlstream.matcher import *
@@ -152,5 +153,50 @@ class TestHandlers(SleekTest):
self.failUnless(events == ['foo'],
"Iq callback was not executed: %s" % events)
+ def testMultipleHandlersForStanza(self):
+ """
+ Test that multiple handlers for a single stanza work
+ without clobbering each other.
+ """
+
+ def handler_1(msg):
+ msg.reply("Handler 1: %s" % msg['body']).send()
+
+ def handler_2(msg):
+ msg.reply("Handler 2: %s" % msg['body']).send()
+
+ def handler_3(msg):
+ msg.reply("Handler 3: %s" % msg['body']).send()
+
+ self.stream_start()
+ self.xmpp.add_event_handler('message', handler_1)
+ self.xmpp.add_event_handler('message', handler_2)
+ self.xmpp.add_event_handler('message', handler_3)
+
+ self.recv("""
+ <message to="tester@localhost" from="user@example.com">
+ <body>Testing</body>
+ </message>
+ """)
+
+
+ # This test is brittle, depending on the fact that handlers
+ # will be checked in the order they are registered.
+ self.send("""
+ <message to="user@example.com">
+ <body>Handler 1: Testing</body>
+ </message>
+ """)
+ self.send("""
+ <message to="user@example.com">
+ <body>Handler 2: Testing</body>
+ </message>
+ """)
+ self.send("""
+ <message to="user@example.com">
+ <body>Handler 3: Testing</body>
+ </message>
+ """)
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestHandlers)