Ejemplo n.º 1
0
async def test_client_end_stream(*args, **kwargs):
    test_transport = asyncio.Transport()
    test_transport.get_extra_info = mock.Mock(
        return_value=mock_transport_extra_info())
    test_transport.write = mock.Mock(return_value=return_send_data)
    xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient.state = xmppclient.CONNECT  # Set client state to CONNECT
    mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)

    # Send end stream from "client"
    test_data = "</stream:stream>".encode("utf-8")
    xmppclient._parse_data(test_data)

    # Expect 2 calls to send
    assert mock_send.call_count == 1
    # Server opens stream
    assert mock_send.mock_calls[0].args[0] == "</stream:stream>"

    # Reset mock calls
    mock_send.reset_mock()

    # Send abnormal stream from "client"
    test_data = "<badstr />".encode("utf-8")
    xmppclient._parse_data(test_data)

    # Reset mock calls
    mock_send.reset_mock()

    # Send blank from "client"
    test_data = "".encode("utf-8")
    xmppclient._parse_data(test_data)
Ejemplo n.º 2
0
    def setUp(self):
        base_manager = base.BaseApplication(self.REALM, self.HOST,
                                            self.HOST_ADDR)
        s6a_manager = s6a_relay.S6AApplication(
            Mock(),
            self.REALM,
            self.HOST,
            self.HOST_ADDR,
        )
        base_manager.register(s6a_manager)
        self._server = server.S6aServer(
            base_manager,
            s6a_manager,
            self.REALM,
            self.HOST,
        )

        # Mock the writes to check responses
        self._writes = Mock()

        def convert_memview_to_bytes(memview):
            """ Deep copy the memoryview for checking later  """
            return self._writes(memview.tobytes())

        self._transport = asyncio.Transport()
        self._transport.write = Mock(side_effect=convert_memview_to_bytes)

        # Here goes nothing..
        self._server.connection_made(self._transport)
Ejemplo n.º 3
0
    def test_get_extra_info(self):
        transport = asyncio.Transport({'extra': 'info'})
        self.assertEqual('info', transport.get_extra_info('extra'))
        self.assertIsNone(transport.get_extra_info('unknown'))

        default = object()
        self.assertIs(default, transport.get_extra_info('unknown', default))
Ejemplo n.º 4
0
 def test_pulsar_protocol(self):
     proto = Protocol(asyncio.get_event_loop())
     self.assertEqual(proto.session, 1)
     self.assertFalse(proto.transport)
     self.assertTrue(proto.closed)
     transport = asyncio.Transport()
     proto.connection_made(transport)
     self.assertEqual(proto.transport, transport)
Ejemplo n.º 5
0
 def test_writelines(self):
     transport = asyncio.Transport()
     transport.write = mock.Mock()
     transport.writelines(
         [b'line1', bytearray(b'line2'),
          memoryview(b'line3')])
     self.assertEqual(1, transport.write.call_count)
     transport.write.assert_called_with(b'line1line2line3')
Ejemplo n.º 6
0
 async def test_server_chunked_request(self):
     blob_hash = "7f5ab2def99f0ddd008da71db3a3772135f4002b19b7605840ed1034c8955431bd7079549e65e6b2a3b9c17c773073ed"
     server_protocol = BlobServerProtocol(self.loop, self.server_blob_manager, self.server.lbrycrd_address)
     transport = asyncio.Transport(extra={'peername': ('ip', 90)})
     received_data = BytesIO()
     transport.write = received_data.write
     server_protocol.connection_made(transport)
     blob_request = BlobRequest.make_request_for_blob_hash(blob_hash).serialize()
     for byte in blob_request:
         server_protocol.data_received(bytes([byte]))
     await asyncio.sleep(0.1)  # yield execution
     self.assertTrue(len(received_data.getvalue()) > 0)
Ejemplo n.º 7
0
 def test_not_implemented(self):
     transport = asyncio.Transport()
     self.assertRaises(NotImplementedError,
                       transport.set_write_buffer_limits)
     self.assertRaises(NotImplementedError, transport.get_write_buffer_size)
     self.assertRaises(NotImplementedError, transport.write, 'data')
     self.assertRaises(NotImplementedError, transport.write_eof)
     self.assertRaises(NotImplementedError, transport.can_write_eof)
     self.assertRaises(NotImplementedError, transport.pause_reading)
     self.assertRaises(NotImplementedError, transport.resume_reading)
     self.assertRaises(NotImplementedError, transport.close)
     self.assertRaises(NotImplementedError, transport.abort)
Ejemplo n.º 8
0
    def setUp(self):
        # Mock the writes to check responses
        self._writes = Mock()

        def convert_memview_to_bytes(memview):
            """ Deep copy the memoryview for checking later  """
            return self._writes(memview.tobytes())

        self._transport = asyncio.Transport()
        self._transport.write = Mock(side_effect=convert_memview_to_bytes)

        self.writer = server.Writer("mai.facebook.com", "hss.mai.facebook.com",
                                    "127.0.0.1", self._transport)
Ejemplo n.º 9
0
    def setUp(self):
        self._ipa = OsmoIPAServer(None)

        # Mock the writes to check responses
        self._writes = Mock()

        def convert_memview_to_bytes(memview):
            """ Deep copy the memoryview for checking later  """
            return self._writes(memview.tobytes())

        self._transport = asyncio.Transport()
        self._transport.write = Mock(side_effect=convert_memview_to_bytes)

        # Here goes nothing..
        self._ipa.connection_made(self._transport)
Ejemplo n.º 10
0
    def test_make_initial_messages(self):
        source_future = self.loop.create_future()

        async def source_consumer(queue):
            count = 0
            while True:
                message = await queue.get()
                count += 1
                if count == 2:
                    source_future.set_result(None)
                queue.task_done()

        self.server.bus.add_consumer(messages.SourceMessage, source_consumer)
        # Create input sources
        sender = self.make_sender("""
            audiotestsrc freq=440 ! {} ! mux.
            videotestsrc ! {} ! mux.
        """.format(self.config.audio_caps.to_string(),
                   self.config.video_caps.to_string()))
        sender.set_state(Gst.State.PLAYING)
        self.loop.run_until_complete(source_future)

        transport = asyncio.Transport({"sockname": ("myhostname", 4242)})
        msgs = self.server.make_initial_messages(transport)
        self.assertEqual(len(msgs), 5)
        mixercfg = msgs[0]
        self.assertIsInstance(mixercfg, messages.MixerConfig)
        self.assertEqual(mixercfg.control_addr,
                         ("myhostname", self.server.control.local_port()))
        self.assertEqual(mixercfg.clock_addr,
                         ("myhostname", self.server.clock.local_port()))
        self.assertEqual(mixercfg.avsource_addr,
                         ("myhostname", self.server.sources.local_port()))
        self.assertEqual(
            mixercfg.avoutput_uri,
            "http://myhostname:{}".format(self.server.outputs.local_port()))
        self.assertEqual(mixercfg.composite_modes,
                         sorted(self.config.composite_modes.keys()))
        self.assertEqual(mixercfg.video_caps,
                         self.config.video_caps.to_string())
        self.assertEqual(mixercfg.audio_caps,
                         self.config.audio_caps.to_string())

        self.assertIsInstance(msgs[1], messages.VideoSourceAdded)
        self.assertIsInstance(msgs[2], messages.AudioSourceAdded)
        self.assertIsInstance(msgs[3], messages.VideoMixStatus)
        self.assertIsInstance(msgs[4], messages.AudioMixStatus)
Ejemplo n.º 11
0
    async def create_connection(protocol_factory, host=None, port=None):
        def write(p: asyncio.Protocol):
            def _write(data):
                sent_tcp_packets.append(data)
                if data in tcp_replies:
                    loop.call_later(tcp_delay_reply, p.data_received,
                                    tcp_replies[data])

            return _write

        protocol = protocol_factory()
        transport = asyncio.Transport(
            extra={'socket': mock.Mock(spec=socket.socket)})
        transport.close = lambda: None
        transport.write = write(protocol)
        protocol.connection_made(transport)
        return transport, protocol
Ejemplo n.º 12
0
    def setUp(self):
        ServiceRegistry.add_service('s6a_proxy', '0.0.0.0', 0)
        proxy_config = {
            'local_port': 1234,
            'cloud_address': 'test',
            'proxy_cloud_connections': True,
        }

        self._base_manager = base.BaseApplication(self.REALM, self.HOST,
                                                  self.HOST_ADDR)
        self._proxy_client = Mock()
        self._s6a_manager = s6a_relay.S6ARelayApplication(
            Mock(),
            self.REALM,
            self.HOST,
            self.HOST_ADDR,
            proxy_client=self._proxy_client,
        )
        self._server = server.S6aServer(
            self._base_manager,
            self._s6a_manager,
            self.REALM,
            self.HOST,
        )

        self.get_proxy_config_patcher = patch.object(
            s6a_relay.ServiceRegistry, 'get_proxy_config',
            Mock(return_value=proxy_config))
        self.mock_get_proxy_config = self.get_proxy_config_patcher.start()
        self.addCleanup(self.get_proxy_config_patcher.stop)

        # Mock the writes to check responses
        self._writes = Mock()

        def convert_memview_to_bytes(memview):
            """ Deep copy the memoryview for checking later  """
            return self._writes(memview.tobytes())

        self._transport = asyncio.Transport()
        self._transport.write = Mock(side_effect=convert_memview_to_bytes)

        # Here goes nothing..
        self._server.connection_made(self._transport)
Ejemplo n.º 13
0
async def test_ping_server(*args, **kwargs):
    test_transport = asyncio.Transport()
    test_transport.get_extra_info = mock.Mock(
        return_value=mock_transport_extra_info())
    test_transport.write = mock.Mock(return_value=return_send_data)
    xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient.state = xmppclient.READY  # Set client state to READY
    xmppclient.uid = "E0000000000000001234"
    xmppclient.devclass = "159"
    mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)

    # Ping from bot
    test_data = '<iq xmlns:ns0="urn:xmpp:ping" from="[email protected]/atom" id="2542" to="159.ecorobot.net" type="get"><ping /></iq>'.encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (mock_send.mock_calls[0].args[0] ==
            '<iq type="result" id="2542" from="159.ecorobot.net" />'
            )  # ping response
Ejemplo n.º 14
0
async def test_ping_client_to_client(*args, **kwargs):

    test_transport = asyncio.Transport()
    test_transport.get_extra_info = mock.Mock(
        return_value=mock_transport_extra_info())
    test_transport.write = mock.Mock(return_value=return_send_data)
    xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient.state = xmppclient.READY  # Set client state to READY
    xmppclient.uid = "E0000000000000001234"
    xmppclient.devclass = "159"
    xmppclient.bumper_jid = "[email protected]/atom"
    mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)

    xmppclient2 = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient2.state = xmppclient.READY  # Set client state to READY
    xmppclient2.uid = "fuid_tmpuser"
    xmppclient2.resource = "IOSF53D07BA"
    xmppclient2.bumper_jid = "[email protected]/IOSF53D07BA"
    mock_send2 = xmppclient2.send = mock.Mock(side_effect=return_send_data)

    bumper.xmppserver.XMPPServer.clients.append(xmppclient)
    bumper.xmppserver.XMPPServer.clients.append(xmppclient2)

    # Ping from user to bot
    test_data = '<iq id="104934615" to="[email protected]/IOSF53D07BA" type="get"><ping xmlns="urn:xmpp:ping" /></iq>'.encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (
        mock_send2.mock_calls[0].args[0] ==
        '<iq from="[email protected]/atom" id="104934615" to="[email protected]/IOSF53D07BA" type="get"><ping xmlns="urn:xmpp:ping" /></iq>'
    )  # ping response

    # Ping response from bot to user
    test_data = "<iq type='result' to='[email protected]/atom' id='104934615'/>".encode(
        "utf-8")
    xmppclient2._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq from="[email protected]/IOSF53D07BA" id="104934615" to="[email protected]/atom" type="result" />'
    )  # ping response
Ejemplo n.º 15
0
    def setUp(self):

        self._server = server.S6aServer(Mock(), Mock(), "mai.facebook.com",
                                        "hss.mai.facebook.com")

        # Mock the message handler
        self._server._handle_msg = Mock()

        # Mock the writes to check responses
        self._writes = Mock()

        def convert_memview_to_bytes(memview):
            """ Deep copy the memoryview for checking later  """
            return self._writes(memview.tobytes())

        self._transport = asyncio.Transport()
        self._transport.write = Mock(side_effect=convert_memview_to_bytes)

        # Here goes nothing..
        self._server.connection_made(self._transport)
Ejemplo n.º 16
0
async def test_bot_connect(*args, **kwargs):
    test_transport = asyncio.Transport()
    test_transport.get_extra_info = mock.Mock(
        return_value=mock_transport_extra_info())
    test_transport.write = mock.Mock(return_value=return_send_data)
    xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient.state = xmppclient.CONNECT  # Set client state to CONNECT
    mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)

    # Send connect stream from "bot"
    test_data = "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>".encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    # Expect 2 calls to send
    assert mock_send.call_count == 2
    # Server opens stream
    assert (
        mock_send.mock_calls[0].args[0] ==
        '<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0" id="1" from="ecouser.net">'
    )
    # Server tells client available features
    assert (
        mock_send.mock_calls[1].args[0] ==
        '<stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required/></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism></mechanisms></stream:features>'
    )

    # Reset mock calls
    mock_send.reset_mock()

    # Send auth from "bot"
    test_data = "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AEUwMDAwMDAwMDAwMDAwMDAxMjM0AGVuY3J5cHRlZF9wYXNz</auth>".encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (mock_send.mock_calls[0].args[0] ==
            '<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>'
            )  # Bot successfully authenticated
    assert xmppclient.state == xmppclient.INIT  # Bot moved to INIT state
    assert xmppclient.type == xmppclient.BOT  # Client type is now bot
Ejemplo n.º 17
0
async def test_client_connect_no_starttls(*args, **kwargs):
    test_transport = asyncio.Transport()
    test_transport.get_extra_info = mock.Mock(
        return_value=mock_transport_extra_info())
    test_transport.write = mock.Mock(return_value=return_send_data)
    xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient.state = xmppclient.CONNECT  # Set client state to CONNECT
    mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)

    # Send connect stream from "client"
    test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    # Expect 2 calls to send
    assert mock_send.call_count == 2
    # Server opens stream
    assert (
        mock_send.mock_calls[0].args[0] ==
        '<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0" id="1" from="ecouser.net">'
    )
    # Server tells client available features
    assert (
        mock_send.mock_calls[1].args[0] ==
        '<stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required/></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism></mechanisms></stream:features>'
    )

    # Reset mock calls
    mock_send.reset_mock()

    # Client sendss auth - Ignoring the starttls, we don't force this with bumper
    test_data = '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">AGZ1aWRfdG1wdXNlcgAwL0lPU0Y1M0QwN0JBL3VzXzg5ODgwMmZkYmM0NDQxYjBiYzgxNWIxZDFjNjgzMDJl</auth>'.encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (mock_send.mock_calls[0].args[0] ==
            '<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>'
            )  # Client successfully authenticated
    assert xmppclient.state == xmppclient.INIT  # Client moved to INIT state
Ejemplo n.º 18
0
async def test_client_init(*args, **kwargs):
    test_transport = asyncio.Transport()
    test_transport.get_extra_info = mock.Mock(
        return_value=mock_transport_extra_info())
    test_transport.write = mock.Mock(return_value=return_send_data)
    xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient.state = xmppclient.INIT  # Set client state to INIT
    xmppclient.uid = "fuid_tmpuser"
    xmppclient.resource = "IOSF53D07BA"
    xmppclient.bumper_jid = "[email protected]/IOSF53D07BA"
    xmppclient.type = xmppclient.CONTROLLER
    mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)

    # Send connect stream from "client"
    test_data = "<stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' to='ecouser.net'>".encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    # Expect 2 calls to send
    assert mock_send.call_count == 2
    # Server opens stream
    assert (
        mock_send.mock_calls[0].args[0] ==
        '<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0" id="1" from="ecouser.net">'
    )
    # Server tells client binds
    assert (
        mock_send.mock_calls[1].args[0] ==
        '<stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>'
    )

    # Reset mock calls
    mock_send.reset_mock()

    # Send bind from "client"
    test_data = '<iq type="set" id="5E9872D5-547E-49AF-AE51-9EFAA282F952"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>IOSF53D07BA</resource></bind></iq>'.encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq type="result" id="5E9872D5-547E-49AF-AE51-9EFAA282F952"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>[email protected]/IOSF53D07BA</jid></bind></iq>'
    )  # client successfully binded
    assert xmppclient.state == xmppclient.BIND  # client moved to BIND state

    # Reset mock calls
    mock_send.reset_mock()

    # Send set session from client
    test_data = '<iq type="set" id="FA1041E7-AA27-43DD-BAA3-64DE2DE56AA3"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>'.encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert xmppclient.state == xmppclient.READY  # client moved to READY state
    assert (mock_send.mock_calls[0].args[0] ==
            '<iq type="result" id="FA1041E7-AA27-43DD-BAA3-64DE2DE56AA3" />'
            )  # client ready

    # Reset mock calls
    mock_send.reset_mock()

    # Send presense from client
    test_data = '<presence type="available"/>'.encode("utf-8")
    xmppclient._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<presence to="[email protected]/IOSF53D07BA"> dummy </presence>'
    )  # client presence - dummy response
Ejemplo n.º 19
0
 def test_ctor_extra_is_none(self):
     transport = asyncio.Transport()
     self.assertEqual(transport._extra, {})
Ejemplo n.º 20
0
async def test_bot_init(*args, **kwargs):
    test_transport = asyncio.Transport()
    test_transport.get_extra_info = mock.Mock(
        return_value=mock_transport_extra_info())
    test_transport.write = mock.Mock(return_value=return_send_data)
    xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient.state = xmppclient.INIT  # Set client state to INIT
    xmppclient.uid = "E0000000000000001234"
    xmppclient.devclass = "159"
    xmppclient.type = xmppclient.BOT
    mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)

    # Send connect stream from "bot"
    test_data = "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' to='159.ecorobot.net' version='1.0'>".encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    # Expect 2 calls to send
    assert mock_send.call_count == 2
    # Server opens stream
    assert (
        mock_send.mock_calls[0].args[0] ==
        '<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0" id="1" from="ecouser.net">'
    )
    # Server tells client binds
    assert (
        mock_send.mock_calls[1].args[0] ==
        '<stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>'
    )

    # Reset mock calls
    mock_send.reset_mock()

    # Send bind from "bot"
    test_data = "<iq type='set' id='2521'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><resource>atom</resource></bind></iq>".encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq type="result" id="2521"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>[email protected]/atom</jid></bind></iq>'
    )  # Bot successfully binded
    assert xmppclient.state == xmppclient.BIND  # Bot moved to BIND state

    # Reset mock calls
    mock_send.reset_mock()

    # Send set session from bot
    test_data = "<iq type='set' id='2522'><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/></iq>".encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert xmppclient.state == xmppclient.READY  # Bot moved to READY state
    assert (mock_send.mock_calls[0].args[0] == '<iq type="result" id="2522" />'
            )  # Bot ready

    # Reset mock calls
    mock_send.reset_mock()

    # Send presense from bot
    test_data = "<presence><status>hello world</status></presence><iq type='result' from='[email protected]/atom' to='ecouser.net' id='s2c1'/>".encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<presence to="[email protected]/atom"> dummy </presence>'
    )  # bot presence - dummy response
Ejemplo n.º 21
0
    def __init__(self):
        self._stream_transport = asyncio.Transport()

        self._incoming = bytearray()

        self._awaiting_the_bittorrent_handshake = True
Ejemplo n.º 22
0
async def test_client_connected(event_loop):
    sp = StreamProtocol(loop=event_loop)
    sp.connection_made(asyncio.Transport())
    assert sp.is_connected() is True
Ejemplo n.º 23
0
async def test_client_send_iq(*args, **kwargs):
    test_transport = asyncio.Transport()
    test_transport.get_extra_info = mock.Mock(
        return_value=mock_transport_extra_info())
    test_transport.write = mock.Mock(return_value=return_send_data)
    xmppclient = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient.state = xmppclient.READY  # Set client state to READY
    xmppclient.uid = "fuid_tmpuser"
    xmppclient.resource = "IOSF53D07BA"
    xmppclient.bumper_jid = "[email protected]/IOSF53D07BA"
    xmppclient.type - xmppclient.CONTROLLER
    mock_send = xmppclient.send = mock.Mock(side_effect=return_send_data)
    bumper.xmppserver.XMPPServer.clients.append(xmppclient)

    xmppclient2 = bumper.xmppserver.XMPPAsyncClient(test_transport)
    xmppclient2.state = xmppclient.READY  # Set client state to READY
    xmppclient2.uid = "E0000000000000001234"
    xmppclient2.devclass = "159"
    xmppclient2.bumper_jid = "[email protected]/atom"
    xmppclient2.type = xmppclient2.BOT
    mock_send2 = xmppclient2.send = mock.Mock(side_effect=return_send_data)

    bumper.xmppserver.XMPPServer.clients.append(xmppclient2)

    # Roster IQ - Only seen from Android app so far
    test_data = '<iq id="EE0XQ-2" type="get"><query xmlns="jabber:iq:roster" ></query></iq>'.encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq type="error" id="EE0XQ-2"><error type="cancel" code="501"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>'
    )  # feature not implemented response

    # Reset mock calls
    mock_send.reset_mock()

    # Bot Command
    test_data = '<iq id="7" to="[email protected]/atom" type="set"><query xmlns="com:ctl"><ctl id="72107787" td="GetCleanState" /></query></iq>'.encode(
        "utf-8")
    xmppclient._parse_data(test_data)

    assert (
        mock_send2.mock_calls[0].args[0] ==
        '<iq from="[email protected]/IOSF53D07BA" id="7" to="[email protected]/atom" type="set"><query xmlns="com:ctl"><ctl id="72107787" td="GetCleanState" /></query></iq>'
    )  # command was sent to bot

    # Reset mock calls
    mock_send.reset_mock()

    # Bot response to query
    test_data = '<iq xmlns:ns0="com:ctl" id="2679" to="[email protected]/IOSF53D07BA" type="set"><query><ctl td="ChargeState"><charge h="0" r="a" type="Going" /></ctl></query></iq>'.encode(
        "utf-8")
    xmppclient2._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq from="[email protected]/atom" id="2679" to="[email protected]/IOSF53D07BA" type="set"><query xmlns="com:ctl"><ctl td="ChargeState"><charge h="0" r="a" type="Going" /></ctl></query></iq>'
    )  # result sent to client

    # Reset mock calls
    mock_send.reset_mock()

    # Bot result
    test_data = "<iq type='result' from='[email protected]/atom' to='ecouser.net' id='s2c1'/>".encode(
        "utf-8")
    xmppclient2._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq from="[email protected]/atom" id="s2c1" to="ecouser.net" type="result" />'
    )  # result sent to ecouser.net

    # Reset mock calls
    mock_send.reset_mock()

    # Bot iq set
    test_data = "<iq to='[email protected]/IOSF53D07BA' type='set' id='2700'><query xmlns='com:ctl'><ctl td='BatteryInfo'><battery power='100'/></ctl></query></iq>".encode(
        "utf-8")
    xmppclient2._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq from="[email protected]/atom" id="2700" to="[email protected]/IOSF53D07BA" type="set"><query xmlns="com:ctl"><ctl td="BatteryInfo"><battery power="100" /></ctl></query></iq>'
    )  # result sent to ecouser.net

    # Reset mock calls
    mock_send.reset_mock()

    # Bot error report
    test_data = "<iq to='[email protected]/IOSF53D07BA' type='set' id='631'><query xmlns='com:ctl'><ctl td='error' errs='102'/></query></iq>".encode(
        "utf-8")
    xmppclient2._parse_data(test_data)

    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq from="[email protected]/atom" id="631" to="[email protected]/IOSF53D07BA" type="set"><query xmlns="com:ctl"><ctl errs="102" td="error" /></query></iq>'
    )  # result sent to ecouser.net

    # Reset mock calls
    mock_send.reset_mock()

    # Bot "DorpError" to all
    test_data = "<iq to='rl.ecorobot.net' type='set' id='1234'><query xmlns='com:sf'><sf td='pub' t='log' ts='1559893796000' tp='p' k='DeviceAlert' v='DorpError' f='*****@*****.**' g='*****@*****.**'/></query></iq>".encode(
        "utf-8")
    xmppclient2._parse_data(test_data)
    assert (
        mock_send.mock_calls[0].args[0] ==
        '<iq xmlns="com:sf" from="[email protected]/atom" id="1234" to="rl.ecorobot.net" type="set"><query xmlns="com:ctl"><sf f="*****@*****.**" g="*****@*****.**" k="DeviceAlert" t="log" td="pub" tp="p" ts="1559893796000" v="DorpError" /></query></iq>'
    )  # result sent to ecouser.net

    # Reset mock calls
    mock_send.reset_mock()