From caa967105c609537050817021a426b0a7e6d54ec Mon Sep 17 00:00:00 2001 From: Lance Stout Date: Fri, 3 Feb 2012 16:29:38 +0100 Subject: [PATCH] Add more XEP-0047 tests. --- sleekxmpp/plugins/xep_0047/stanza.py | 2 +- tests/test_stream_xep_0047.py | 82 ++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/sleekxmpp/plugins/xep_0047/stanza.py b/sleekxmpp/plugins/xep_0047/stanza.py index f5b77c0..fb0d430 100644 --- a/sleekxmpp/plugins/xep_0047/stanza.py +++ b/sleekxmpp/plugins/xep_0047/stanza.py @@ -46,7 +46,7 @@ class Data(ElementBase): self._set_attr('seq', str(value)) def get_data(self): - b64_data = self.xml.text + b64_data = self.xml.text.strip() if VALID_B64.match(b64_data).group() == b64_data: return from_b64(b64_data) else: diff --git a/tests/test_stream_xep_0047.py b/tests/test_stream_xep_0047.py index 485dafe..d8cdd6a 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(""" + + + + """) + + self.recv(""" + + """) + + t.join() + + time.sleep(0.2) + + stream = streams[0] + + + # Test sending data out + stream.send("Testing") + + self.send(""" + + + VGVzdGluZw== + + + """) + + self.recv(""" + + """) + + # Test receiving data + self.recv(""" + + + aXQgd29ya3Mh + + + """) + + self.send(""" + + """) + + self.assertEqual(data, ['it works!']) suite = unittest.TestLoader().loadTestsFromTestCase(TestInBandByteStreams)