Add unit test for copying stanzas when passed to events.

This commit is contained in:
Lance Stout 2011-11-19 18:43:38 -08:00
parent b54cc97e4c
commit f9d0b55ca3

View file

@ -1,5 +1,6 @@
import time import time
from sleekxmpp import Message
from sleekxmpp.test import * from sleekxmpp.test import *
from sleekxmpp.xmlstream.handler import * from sleekxmpp.xmlstream.handler import *
from sleekxmpp.xmlstream.matcher import * from sleekxmpp.xmlstream.matcher import *
@ -152,5 +153,50 @@ class TestHandlers(SleekTest):
self.failUnless(events == ['foo'], self.failUnless(events == ['foo'],
"Iq callback was not executed: %s" % events) "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) suite = unittest.TestLoader().loadTestsFromTestCase(TestHandlers)