예제 #1
0
async def test_websocket_close_reconnect(client, protocol_client, websocket_list, websocket):
    websocket_list.get.side_effect = [
        async_return_value(["wss://abc.com/websocket"]),
        async_return_value(["wss://abc.com/websocket"])
    ]
    protocol_client.run.side_effect = [
        async_raise(websockets.ConnectionClosedError(1002, ""), 10),
        async_raise(AssertionError)
    ]
    credentials_mock = {'password': PASSWORD, "two_factor": TWO_FACTOR}
    plugin_queue_mock = AsyncMock()
    websocket_queue_mock = AsyncMock()
    websocket_queue_mock.get.return_value = credentials_mock
    error_queue_mock = AsyncMock()
    error_queue_mock.get.return_value = MagicMock()
    client.communication_queues = {'plugin': plugin_queue_mock, 'websocket': websocket_queue_mock, 'errors': error_queue_mock}

    protocol_client.close.return_value = async_return_value(None)
    protocol_client.wait_closed.return_value = async_return_value(None)
    protocol_client.authenticate_token = AsyncMock()
    protocol_client.authenticate_token.return_value = async_return_value(None)

    websocket.close.return_value = async_return_value(None)
    websocket.wait_closed.return_value = async_return_value(None)

    client._user_info_cache = MagicMock()
    client._user_info_cache.old_flow = False
    with pytest.raises(AssertionError):
        await client.run()

    assert websocket_list.get.call_count == 2
    assert protocol_client.authenticate_token.call_count == 2
    assert protocol_client.run.call_count == 2
예제 #2
0
async def test_websockets_closed(mocker, capsys):
    websocket = mocker.patch("websockets.connect")
    dummy_resp = "test\n"
    repeat = 0
    exception = websockets.ConnectionClosedError(1008, "")
    websocket.return_value = DummyWebSocketClientProtcol(
        dummy_resp, repeat, exception)
    await entry_point("")
    captured = capsys.readouterr()
    assert captured.out == "Connection closed\n"
예제 #3
0
async def test_websocket_close_reconnect(client, protocol_client, backend_client, servers_cache, websocket):
    servers_cache.get.side_effect = [
        async_return_value(["wss://abc.com/websocket"]),
        async_return_value(["wss://abc.com/websocket"])
    ]
    backend_client.get_authentication_data.return_value = STEAM_ID, ACCOUNT_NAME, TOKEN
    protocol_client.authenticate.return_value = async_return_value(None)
    protocol_client.run.side_effect = [
        async_raise(websockets.ConnectionClosedError(1002, ""), 10),
        async_raise(websockets.ConnectionClosedOK(1000, ""), 10)
    ]
    protocol_client.close.return_value = async_return_value(None)
    protocol_client.wait_closed.return_value = async_return_value(None)
    websocket.close.return_value = async_return_value(None)
    websocket.wait_closed.return_value = async_return_value(None)
    await client.run()
    assert servers_cache.get.call_count == 2
    assert protocol_client.authenticate.call_count == 2
    assert protocol_client.run.call_count == 2