'Test sending data over an in-band bytestream.'

def testSendData(self):

    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('\n                                        <iq    type="set"    to="tester@localhost/receiver"    id="1">\n                                                <open    xmlns="http://jabber.org/protocol/ibb"\n                                                                        sid="testing"\n                                                                        block-size="4096"\n                                                                        stanza="iq"    />\n                                        </iq>\n                                ')
    self.recv('\n                                        <iq    type="result"    id="1"\n                                                        to="tester@localhost"\n                                                        from="tester@localhost/receiver"    />\n                                ')
    t.join()
    time.sleep(0.2)
    stream = streams[0]
    stream.send('Testing')
    self.send('\n                                        <iq    type="set"    id="2"\n                                                        from="tester@localhost"\n                                                        to="tester@localhost/receiver">\n                                                <data    xmlns="http://jabber.org/protocol/ibb"\n                                                                        seq="0"\n                                                                        sid="testing">\n                                                        VGVzdGluZw==\n                                                </data>\n                                        </iq>\n                                ')
    self.recv('\n                                        <iq    type="result"    id="2"\n                                                        to="tester@localhost"\n                                                        from="tester@localhost/receiver"    />\n                                ')
    self.recv('\n                                        <iq    type="set"    id="A"\n                                                        to="tester@localhost"\n                                                        from="tester@localhost/receiver">\n                                                <data    xmlns="http://jabber.org/protocol/ibb"\n                                                                        seq="0"\n                                                                        sid="testing">\n                                                        aXQgd29ya3Mh\n                                                </data>\n                                        </iq>\n                                ')
    self.send('\n                                        <iq    type="result"    id="A"\n                                                        to="tester@localhost/receiver"    />\n                                ')
    self.assertEqual(data, ['it    works!'])
