Ejemplo n.º 1
0
def test_binary_content_raises_error():
    r = receiver.Receiver(_proto)

    r.consume(decode_utf8('header'))
    r.consume(decode_utf8('metadata'))
    with pytest.raises(ValidationError):
        r.consume(b'content').result()
Ejemplo n.º 2
0
def test_multiple_validation_success_with_multiple_buffers():
    r = receiver.Receiver(_proto)

    for N in range(10):
        partial = r.consume(
            decode_utf8(
                '{"msgtype": "PATCH-DOC", "msgid": "10", "num_buffers":%d}' %
                N)).result()
        partial = r.consume(decode_utf8('{}')).result()
        partial = r.consume(decode_utf8('{"bar": 10}')).result()

        for i in range(N):
            partial = r.consume(decode_utf8('header%d' % i)).result()
            partial = r.consume(b'payload%d' % i).result()

        assert partial is not None
        assert partial.msgtype == "PATCH-DOC"
        assert partial.header == {
            "msgtype": "PATCH-DOC",
            "msgid": "10",
            "num_buffers": N
        }
        assert partial.content == {"bar": 10}
        assert partial.metadata == {}
        assert partial.buffers == [('header%d' % i, b'payload%d' % i)
                                   for i in range(N)]
Ejemplo n.º 3
0
async def test_multiple_validation_success_with_multiple_buffers() -> None:
    r = receiver.Receiver(proto)

    for N in range(10):
        partial = await r.consume(
            f'{{"msgtype": "PATCH-DOC", "msgid": "10", "num_buffers":{N}}}')
        partial = await r.consume('{}')
        partial = await r.consume('{"bar": 10}')

        for i in range(N):
            partial = await r.consume(f'{{"id": "header{i}"}}')
            partial = await r.consume(f'payload{i}'.encode())

        assert partial is not None
        assert partial.msgtype == "PATCH-DOC"
        assert partial.header == {
            "msgtype": "PATCH-DOC",
            "msgid": "10",
            "num_buffers": N
        }
        assert partial.content == {"bar": 10}
        assert partial.metadata == {}
        for i in range(N):
            assert partial.buffers[i] == Buffer(ID(f"header{i}"),
                                                f"payload{i}".encode())
Ejemplo n.º 4
0
async def test_binary_content_raises_error() -> None:
    r = receiver.Receiver(proto)

    await r.consume('header')
    await r.consume('metadata')
    with pytest.raises(ValidationError):
        await r.consume(b'content')
Ejemplo n.º 5
0
async def test_binary_content_raises_error() -> None:
    r = receiver.Receiver(proto)

    await r.consume('{"msgtype": "PATCH-DOC", "msgid": "10"}')
    await r.consume('metadata')
    with pytest.raises(ValidationError):
        await r.consume(b'content')
Ejemplo n.º 6
0
def test_validation_success_with_one_buffer():
    r = receiver.Receiver(_proto)

    partial = r.consume(
        decode_utf8('{"msgtype": "PATCH-DOC", "msgid": "10", "num_buffers":1}')
    ).result()
    assert partial is None

    partial = r.consume(decode_utf8('{}')).result()
    assert partial is None

    partial = r.consume(decode_utf8('{"bar": 10}')).result()
    assert partial is None

    partial = r.consume(decode_utf8('header')).result()
    assert partial is None

    partial = r.consume(b'payload').result()
    assert partial is not None
    assert partial.msgtype == "PATCH-DOC"
    assert partial.header == {
        "msgtype": "PATCH-DOC",
        "msgid": "10",
        "num_buffers": 1
    }
    assert partial.content == {"bar": 10}
    assert partial.metadata == {}
    assert partial.buffers == [('header', b'payload')]
Ejemplo n.º 7
0
async def test_validation_success_with_one_buffer() -> None:
    r = receiver.Receiver(proto)

    partial = await r.consume(
        '{"msgtype": "PATCH-DOC", "msgid": "10", "num_buffers":1}')
    assert partial is None

    partial = await r.consume('{}')
    assert partial is None

    partial = await r.consume('{"bar": 10}')
    assert partial is None

    partial = await r.consume('header')
    assert partial is None

    partial = await r.consume(b'payload')
    assert partial is not None
    assert partial.msgtype == "PATCH-DOC"
    assert partial.header == {
        "msgtype": "PATCH-DOC",
        "msgid": "10",
        "num_buffers": 1
    }
    assert partial.content == {"bar": 10}
    assert partial.metadata == {}
    assert partial.buffers == [('header', b'payload')]
Ejemplo n.º 8
0
async def test_binary_payload_header_raises_error() -> None:
    r = receiver.Receiver(proto)

    await r.consume('{"msgtype": "PATCH-DOC", "msgid": "10", "num_buffers":1}')
    await r.consume('{}')
    await r.consume('{}')
    with pytest.raises(ValidationError):
        await r.consume(b'buf_header')
Ejemplo n.º 9
0
def test_binary_payload_header_raises_error():
    r = receiver.Receiver(_proto)

    r.consume(decode_utf8('{"msgtype": "PATCH-DOC", "msgid": "10", "num_buffers":1}'))
    r.consume(decode_utf8('{}'))
    r.consume(decode_utf8('{}'))
    with pytest.raises(ValidationError):
        r.consume(b'buf_header').result()
Ejemplo n.º 10
0
def test_text_payload_buffer_raises_error():
    r = receiver.Receiver(_proto)

    r.consume('{"msgtype": "PATCH-DOC", "msgid": "10", "num_buffers":1}')
    r.consume('{}')
    r.consume('{}')
    r.consume('buf_header').result()
    with pytest.raises(ValidationError):
        r.consume('buf_payload').result()
Ejemplo n.º 11
0
async def test_validation_success() -> None:
    msg = proto.create('ACK')
    r = receiver.Receiver(proto)

    partial = await r.consume(msg.header_json)
    assert partial is None

    partial = await r.consume(msg.metadata_json)
    assert partial is None

    partial = await r.consume(msg.content_json)
    assert partial is not None
    assert partial.msgtype == msg.msgtype
    assert partial.header == msg.header
    assert partial.content == msg.content
    assert partial.metadata == msg.metadata
Ejemplo n.º 12
0
def test_validation_success():
    msg = _proto.create('ACK')
    r = receiver.Receiver(_proto)

    partial = r.consume(decode_utf8(msg.header_json)).result()
    assert partial is None

    partial = r.consume(decode_utf8(msg.metadata_json)).result()
    assert partial is None

    partial = r.consume(decode_utf8(msg.content_json)).result()
    assert partial is not None
    assert partial.msgtype == msg.msgtype
    assert partial.header == msg.header
    assert partial.content == msg.content
    assert partial.metadata == msg.metadata
Ejemplo n.º 13
0
def test_creation() -> None:
    receiver.Receiver(None)
Ejemplo n.º 14
0
async def test_binary_metadata_raises_error():
    r = receiver.Receiver(proto)

    await r.consume('header')
    with pytest.raises(ValidationError):
        await r.consume(b'metadata')
Ejemplo n.º 15
0
def test_binary_header_raises_error():
    r = receiver.Receiver(_proto)

    with pytest.raises(ValidationError):
        r.consume(b'header').result()
Ejemplo n.º 16
0
async def test_binary_header_raises_error() -> None:
    r = receiver.Receiver(proto)

    with pytest.raises(ValidationError):
        await r.consume(b'header')
Ejemplo n.º 17
0
async def test_binary_header_raises_error() -> None:
    r = receiver.Receiver(proto)

    with pytest.raises(ValidationError):
        await r.consume(b'{"msgtype": "PATCH-DOC", "msgid": "10"}')