summaryrefslogtreecommitdiff
path: root/tests/test_stream_xep_0047.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-02-03 16:03:46 +0100
committerLance Stout <lancestout@gmail.com>2012-02-03 16:03:46 +0100
commit85dd005abc9496314f954ed6dbdc22f79387c308 (patch)
treec1abd31901fbd73c53189a1eeec396a0159c40fc /tests/test_stream_xep_0047.py
parent021c57205f79919703354cb2a01ac939e9b4afe2 (diff)
downloadslixmpp-85dd005abc9496314f954ed6dbdc22f79387c308.tar.gz
slixmpp-85dd005abc9496314f954ed6dbdc22f79387c308.tar.bz2
slixmpp-85dd005abc9496314f954ed6dbdc22f79387c308.tar.xz
slixmpp-85dd005abc9496314f954ed6dbdc22f79387c308.zip
Fix infinite callback loop.
Diffstat (limited to 'tests/test_stream_xep_0047.py')
-rw-r--r--tests/test_stream_xep_0047.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/test_stream_xep_0047.py b/tests/test_stream_xep_0047.py
new file mode 100644
index 00000000..485dafe5
--- /dev/null
+++ b/tests/test_stream_xep_0047.py
@@ -0,0 +1,98 @@
+import threading
+import time
+
+from sleekxmpp.test import *
+
+
+class TestInBandByteStreams(SleekTest):
+
+ def setUp(self):
+ self.stream_start(plugins=['xep_0047', 'xep_0030'])
+
+ def tearDown(self):
+ self.stream_close()
+
+ def testOpenStream(self):
+ """Test requesting a stream, successfully"""
+
+ events = []
+
+ def on_stream_start(stream):
+ events.append('ibb_stream_start')
+
+
+ self.xmpp.add_event_handler('ibb_stream_start', on_stream_start)
+
+ t = threading.Thread(name='open_stream',
+ target=self.xmpp['xep_0047'].open_stream,
+ args=('tester@localhost/receiver',),
+ kwargs={'sid': 'testing'})
+ t.start()
+
+ self.send("""
+ <iq type="set" to="tester@localhost/receiver" id="1">
+ <open xmlns="http://jabber.org/protocol/ibb"
+ sid="testing"
+ block-size="4096"
+ stanza="iq" />
+ </iq>
+ """)
+
+ self.recv("""
+ <iq type="result" id="1"
+ to="tester@localhost"
+ from="tester@localhost/receiver" />
+ """)
+
+ t.join()
+
+ time.sleep(0.2)
+
+ self.assertEqual(events, ['ibb_stream_start'])
+
+ def testAysncOpenStream(self):
+ """Test requesting a stream, aysnc"""
+
+ events = set()
+
+ def on_stream_start(stream):
+ events.add('ibb_stream_start')
+
+ def stream_callback(iq):
+ events.add('callback')
+
+ self.xmpp.add_event_handler('ibb_stream_start', on_stream_start)
+
+ t = threading.Thread(name='open_stream',
+ target=self.xmpp['xep_0047'].open_stream,
+ args=('tester@localhost/receiver',),
+ kwargs={'sid': 'testing',
+ 'block': False,
+ 'callback': stream_callback})
+ t.start()
+
+ self.send("""
+ <iq type="set" to="tester@localhost/receiver" id="1">
+ <open xmlns="http://jabber.org/protocol/ibb"
+ sid="testing"
+ block-size="4096"
+ stanza="iq" />
+ </iq>
+ """)
+
+ self.recv("""
+ <iq type="result" id="1"
+ to="tester@localhost"
+ from="tester@localhost/receiver" />
+ """)
+
+ t.join()
+
+ time.sleep(0.2)
+
+ self.assertEqual(events, set(['ibb_stream_start', 'callback']))
+
+
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestInBandByteStreams)