Exemplo n.º 1
0
def send_receive_message(server, client):
    """
    Common test utility to test sending a request/response exchange between
    client and server.

    Sends:
    Client ---"Hello"---> Server ---"World"---> Client
    """
    msg_data = "Hello"
    msg = Message(data=msg_data, codec=Codec())
    client.send(msg.to_buffer())
    server.accept_connection()
    recv = Message.from_buffer(
        data=server.receive(len(msg.data)), codec=Codec()
    )
    # Server received data
    assert recv.data == msg_data
    msg_data = "World"
    resp = Message(data=msg_data, codec=Codec())
    server.send(resp.to_buffer())
    recv = Message.from_buffer(
        data=client.receive(len(resp.data)), codec=Codec()
    )
    # Client received response
    assert recv.data == msg_data
Exemplo n.º 2
0
def test_basic_message():
    codec = Codec()
    buff = b'Hello world'
    assert isinstance(buff, bytes)
    message = Message.from_buffer(buff, codec)
    assert isinstance(message, Message)
    assert isinstance(message.data, str)
    assert isinstance(message.codec, Codec)
    assert b'Hello world' == message.to_buffer()
Exemplo n.º 3
0
def send_receive_message(server, client):
    """
    Client ---"Hello"---> Server ---"World"---> Client
    """
    msg_data = 'Hello'
    msg = Message(data=msg_data, codec=Codec())
    client.send(msg.to_buffer())
    server.accept_connection()
    recv = Message.from_buffer(data=server.receive(len(msg.data)),
                               codec=Codec())
    # Server received data
    assert recv.data == msg_data
    msg_data = 'World'
    resp = Message(data=msg_data, codec=Codec())
    server.send(resp.to_buffer())
    recv = Message.from_buffer(data=client.receive(len(resp.data)),
                               codec=Codec())
    # Client received response
    assert recv.data == msg_data