Пример #1
0
    async def test_downlink_view_open(self, mock_websocket_connect):
        message = '@event(node:"boo/bar",lane:shop)'
        MockWebsocket.get_mock_websocket().messages_to_send.append(message)
        loop_class = ReceiveLoop()
        MockWebsocket.get_mock_websocket(
        ).custom_recv_func = loop_class.recv_loop
        # Given
        with SwimClient(debug=True) as client:
            downlink = ValueDownlinkView(client)
            downlink.set_host_uri('ws://127.0.0.1')
            downlink.set_node_uri('boo/bar')
            downlink.set_lane_uri('shop')
            downlink.did_set(mock_did_set_confirmation)
            # When
            actual = downlink.open()

            while loop_class.call_count == 0:
                pass

            # Then
            self.assertTrue(actual.is_open)

        # await asyncio.sleep(2)
        # self.assertFalse(actual.is_open)
        self.assertTrue(mock_websocket_connect.called)
        self.assertIsInstance(actual.model, DownlinkModel)
Пример #2
0
    async def test_swim_client_get_connection(self, mock_get_connection):
        # Given
        host_uri = 'ws://*****:*****@synced(node:"moo",lane:"cow")')

        with SwimClient() as swim_client:
            downlink_view = swim_client.downlink_value()
            downlink_view._host_uri = host_uri
            downlink_view._node_uri = node_uri
            downlink_view._lane_uri = lane_uri
            # When
            await swim_client._get_connection(host_uri)

        # Then
        mock_get_connection.assert_called_once_with(host_uri)
Пример #3
0
    async def test_swim_client_remove_downlink_view(self, mock_remove_downlink,
                                                    mock_add_downlink):
        # Given
        host_uri = 'ws://*****:*****@synced(node:"moo",lane:"cow")')

        with SwimClient() as swim_client:
            downlink_view = swim_client.downlink_value()
            downlink_view.host_uri = host_uri
            downlink_view.node_uri = node_uri
            downlink_view.lane_uri = lane_uri
            await swim_client.add_downlink_view(downlink_view)
            # When
            await swim_client.remove_downlink_view(downlink_view)

        # Then
        mock_add_downlink.assert_called_once_with(downlink_view)
        mock_remove_downlink.assert_called_once_with(downlink_view)
Пример #4
0
    def test_swim_client_command(self, mock_websocket_connect):
        # Given
        host_uri = 'ws://*****:*****@command(node:moo,lane:cow)"Hello, World!"'
        with SwimClient() as swim_client:
            # When
            actual = swim_client.command(host_uri, node_uri, lane_uri, Text.create_from('Hello, World!'))
            while not actual.done():
                pass

        # Then
        self.assertIsInstance(actual, futures.Future)
        mock_websocket_connect.assert_called_once_with(host_uri)
        self.assertEqual(expected, MockWebsocket.get_mock_websocket().sent_messages[0])
Пример #5
0
 def setUp(self):
     MockWebsocket.clear()
     MockScheduleTask.clear()
     MockExceptionOnce.clear()
     asyncio.get_event_loop().stop()
     asyncio.get_event_loop().close()