diff options
author | Lance Stout <lancestout@gmail.com> | 2012-02-03 16:29:38 +0100 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2012-02-03 16:29:38 +0100 |
commit | caa967105c609537050817021a426b0a7e6d54ec (patch) | |
tree | be3c308036d9b40c61c3486a2f941fb3e9e61582 /tests/test_stream_xep_0047.py | |
parent | d565e4be2084eee14b93c753765b82b5d0f00cd1 (diff) | |
download | slixmpp-caa967105c609537050817021a426b0a7e6d54ec.tar.gz slixmpp-caa967105c609537050817021a426b0a7e6d54ec.tar.bz2 slixmpp-caa967105c609537050817021a426b0a7e6d54ec.tar.xz slixmpp-caa967105c609537050817021a426b0a7e6d54ec.zip |
Add more XEP-0047 tests.
Diffstat (limited to 'tests/test_stream_xep_0047.py')
-rw-r--r-- | tests/test_stream_xep_0047.py | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/test_stream_xep_0047.py b/tests/test_stream_xep_0047.py index 485dafe5..d8cdd6a3 100644 --- a/tests/test_stream_xep_0047.py +++ b/tests/test_stream_xep_0047.py @@ -92,7 +92,89 @@ class TestInBandByteStreams(SleekTest): self.assertEqual(events, set(['ibb_stream_start', 'callback'])) + def testSendData(self): + """Test sending data over an in-band bytestream.""" + streams = [] + data = [] + + def on_stream_start(stream): + streams.append(stream) + + def on_stream_data(d): + data.append(d['data']) + + self.xmpp.add_event_handler('ibb_stream_start', on_stream_start) + self.xmpp.add_event_handler('ibb_stream_data', on_stream_data) + + 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) + + stream = streams[0] + + + # Test sending data out + stream.send("Testing") + + self.send(""" + <iq type="set" id="2" + from="tester@localhost" + to="tester@localhost/receiver"> + <data xmlns="http://jabber.org/protocol/ibb" + seq="0" + sid="testing"> + VGVzdGluZw== + </data> + </iq> + """) + + self.recv(""" + <iq type="result" id="2" + to="tester@localhost" + from="tester@localhost/receiver" /> + """) + + # Test receiving data + self.recv(""" + <iq type="set" id="A" + to="tester@localhost" + from="tester@localhost/receiver"> + <data xmlns="http://jabber.org/protocol/ibb" + seq="0" + sid="testing"> + aXQgd29ya3Mh + </data> + </iq> + """) + + self.send(""" + <iq type="result" id="A" + to="tester@localhost/receiver" /> + """) + + self.assertEqual(data, ['it works!']) suite = unittest.TestLoader().loadTestsFromTestCase(TestInBandByteStreams) |