summaryrefslogtreecommitdiff
path: root/tests/test_stream_handlers.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-12-07 17:19:39 -0500
committerLance Stout <lancestout@gmail.com>2010-12-07 17:19:39 -0500
commit5f2fc67c40f0cd73bee7b2cf3bc3a73d83832a50 (patch)
treecff5c77f3685a4eecd907a31226e402ed46cf32c /tests/test_stream_handlers.py
parent8ead33fc3bdb75312c3112db5001cf9544566efb (diff)
downloadslixmpp-5f2fc67c40f0cd73bee7b2cf3bc3a73d83832a50.tar.gz
slixmpp-5f2fc67c40f0cd73bee7b2cf3bc3a73d83832a50.tar.bz2
slixmpp-5f2fc67c40f0cd73bee7b2cf3bc3a73d83832a50.tar.xz
slixmpp-5f2fc67c40f0cd73bee7b2cf3bc3a73d83832a50.zip
Added option for iq.send to accept a callhandler.
The callback will be a stream level handler, and will not execute in its own thread. If you must have a thread, have the callback function raise a custom event, which can be processed by another event handler, which may run in an individual thread, like so: def handle_reply(self, iq): self.event('custom_event', iq) def do_long_operation_in_thread(self, iq): ... self.add_event_handler('custom_event', self.do_long_operation_in_thread) ...take out already prepared iq stanza... iq.send(callback=self.handle_reply)
Diffstat (limited to 'tests/test_stream_handlers.py')
-rw-r--r--tests/test_stream_handlers.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_stream_handlers.py b/tests/test_stream_handlers.py
index 2b878b37..a475b36c 100644
--- a/tests/test_stream_handlers.py
+++ b/tests/test_stream_handlers.py
@@ -1,3 +1,5 @@
+import time
+
from sleekxmpp.test import *
from sleekxmpp.xmlstream.handler import *
from sleekxmpp.xmlstream.matcher import *
@@ -108,5 +110,41 @@ class TestHandlers(SleekTest):
self.failUnless(waiter_exists == False,
"Waiter handler was not removed.")
+ def testIqCallback(self):
+ """Test that iq.send(callback=handle_foo) works."""
+ events = []
+
+ def handle_foo(iq):
+ events.append('foo')
+
+ iq = self.Iq()
+ iq['type'] = 'get'
+ iq['id'] = 'test-foo'
+ iq['to'] = 'user@localhost'
+ iq['query'] = 'foo'
+ iq.send(callback=handle_foo)
+
+ self.send("""
+ <iq type="get" id="test-foo" to="user@localhost">
+ <query xmlns="foo" />
+ </iq>
+ """)
+
+ self.recv("""
+ <iq type="result" id="test-foo"
+ to="test@localhost"
+ from="user@localhost">
+ <query xmlns="foo">
+ <data />
+ </query>
+ </iq>
+ """)
+
+ # Give event queue time to process
+ time.sleep(0.1)
+
+ self.failUnless(events == ['foo'],
+ "Iq callback was not executed: %s" % events)
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestHandlers)