Beispiel #1
0
async def test_async_raise(client_with_server: Client) -> None:
    convo = client_with_server.convo('async_raise')

    with pytest.raises(ResponseException) as excinfo:
        await convo.send_and_expect({})

    assert 'foo' in excinfo.value.error_types
Beispiel #2
0
async def test_unknown_action(client_with_server: Client) -> None:
    convo = client_with_server.convo('this_action_is_fake')

    with pytest.raises(ResponseException) as excinfo:
        await convo.send_and_expect({})

    assert excinfo.match('Invalid action')
Beispiel #3
0
async def test_unique_error_nonasync(client_with_server: Client) -> None:
    convo = client_with_server.convo('raise_unique_error')

    with pytest.raises(ResponseException) as excinfo:
        await convo.send_and_expect({})

    assert excinfo.value.data.get(
        'exc_class') == 'UniqueError', 'Expecting UniqueError non-async'
Beispiel #4
0
async def test_whoami(client_with_server: Client) -> None:
    convo = client_with_server.convo('whoami')

    reply = await convo.send_and_expect({})

    my_id = reply.data.get('id')

    assert my_id, 'Did not receive an ID from whoami'
    assert isinstance(my_id, int), 'Is not int'
Beispiel #5
0
async def test_invalid_room(
    get_server: Callable[[], ServerTestingServer],
    free_port: int,
) -> None:
    server = get_server()
    server.serve(daemon=True)

    with pytest.raises(Exception) as excinfo:
        client = Client(f'ws://{HOSTNAME}:{free_port}/incorrect')

        async with client:
            convo = client.convo('timeout')
            await convo.send_and_expect({})  # Should never call

    assert excinfo.value.data.get(
        'exc_class') == 'RouterConnectionError', 'Expecting connection failure'
    assert excinfo.value.message.startswith('Path must be')

    server.stop_serve()
Beispiel #6
0
async def test_convo(client_with_server: Client) -> None:
    convo = client_with_server.convo('test_conversation')
    response = await convo.send_and_expect({'arg': 'yo'})

    assert response.data.get('foo1') == 'You said yo'
    assert response.data.get('foo2') == 'is yo'

    response = await convo.send_and_expect({'arg': 'ok'})

    assert response.data.get('data') == 'What is 2+2?'

    await convo.send(data=dict(arg=4))
Beispiel #7
0
async def test_server_timeout(client_with_server: Client) -> None:
    convo = client_with_server.convo('server_timeout_test')

    with pytest.raises(ResponseException) as excinfo:
        # Send nothing and we should get yo back
        response = await convo.send_and_expect({})

        assert response.data.get('data') == 'yo'

        # Server is now expecting a response back but it should timeout by itself
        # so wait until it timeouts and raise exception inside expect()

        await convo.expect(2.0)

    assert excinfo.value.data.get(
        'exc_class'
    ) == 'DispatchAwaitTimeout', 'Timeout server exception class'
Beispiel #8
0
async def test_client_timeout(client_with_server: Client) -> None:
    convo = client_with_server.convo('client_timeout_test')

    with pytest.raises(ResponseTimeoutException) as excinfo:
        await convo.send_and_expect({'timeout': 0.2}, timeout=0.1)
Beispiel #9
0
	def func() -> Client:
		return Client(f'ws://{HOSTNAME}:{free_port}/foo/bar')