mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-27 19:19:54 +00:00
Add unit test for copying stanzas when passed to events.
This commit is contained in:
parent
b54cc97e4c
commit
f9d0b55ca3
1 changed files with 46 additions and 0 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue