Ejemplo n.º 1
0
async def test_unary_stream_simple(loop):
    async with ClientServer(loop=loop) as (handler, stub):
        replies = await stub.Benzine(SavoysRequest(kyler='eediot'))
        assert handler.log == [SavoysRequest(kyler='eediot')]
        assert replies == [GoowyChunk(biomes='papists'),
                           GoowyChunk(biomes='tip'),
                           GoowyChunk(biomes='off')]
Ejemplo n.º 2
0
async def test_unary_unary_advanced(loop):
    async with ClientServer(loop=loop) as (handler, stub):
        async with stub.Plaster.open() as stream:
            await stream.send_message(SavoysRequest(kyler='huizhou'))
            reply = await stream.recv_message()
        assert reply == SavoysReply(benito='bebops')
        assert handler.log == [SavoysRequest(kyler='huizhou')]
Ejemplo n.º 3
0
async def test_unary_stream_advanced(loop):
    async with ClientServer(loop=loop) as (handler, stub):
        async with stub.Benzine.open() as stream:
            await stream.send_message(SavoysRequest(kyler='eediot'), end=True)
            replies = [r async for r in stream]
        assert handler.log == [SavoysRequest(kyler='eediot')]
        assert replies == [GoowyChunk(biomes='papists'),
                           GoowyChunk(biomes='tip'),
                           GoowyChunk(biomes='off')]
Ejemplo n.º 4
0
async def test_exit_and_connection_was_broken(loop):
    client_h2c, server_h2c = create_connections()

    to_client_transport = TransportStub(client_h2c)
    to_server_transport = TransportStub(server_h2c)

    client_conn = Connection(client_h2c, to_server_transport, loop=loop)
    server_conn = Connection(server_h2c, to_client_transport, loop=loop)

    server_proc = EventsProcessor(DummyHandler(), server_conn)
    client_proc = EventsProcessor(DummyHandler(), client_conn)

    request = Request('POST', 'http', '/', authority='test.com')
    client_h2_stream = client_conn.create_stream()
    await client_h2_stream.send_request(request.to_headers(),
                                        _processor=client_proc)

    request = SavoysRequest(kyler='cloth')
    await send_message(client_h2_stream, request, SavoysRequest, end=True)
    to_server_transport.process(server_proc)

    server_h2_stream = server_proc.handler.stream
    request_metadata = Metadata.from_headers(server_proc.handler.headers)

    with pytest.raises(WriteError):
        async with Stream(server_h2_stream,
                          Cardinality.UNARY_UNARY,
                          SavoysRequest,
                          SavoysReply,
                          metadata=request_metadata) as server_stream:
            await server_stream.recv_message()

            # simulate broken connection
            to_client_transport.__raise_on_write__(WriteError)
Ejemplo n.º 5
0
async def test_method_unimplemented(stub):
    with pytest.raises(GRPCError) as err:
        async with stub.stream:
            await stub.stream.send_message(SavoysRequest(kyler='bhatta'),
                                           end=True)

            events = stub.server.events()
            stream_id = events[-1].stream_id

            stub.server.connection.send_headers(
                stream_id,
                [(':status', '200'),
                 ('grpc-status', str(Status.UNIMPLEMENTED.value))],
            )
            stub.server.connection.send_data(
                stream_id,
                encode_message(SavoysReply(benito='giselle')),
            )
            stub.server.connection.send_headers(
                stream_id,
                [('grpc-status', str(Status.OK.value))],
                end_stream=True,
            )
            stub.server.flush()

            assert await stub.stream.recv_message()
    err.match('UNIMPLEMENTED')
Ejemplo n.º 6
0
async def test_unary_unary(stream, stub):
    stub.__headers__.put_nowait([
        (':status', '200'),
        ('content-type', CONTENT_TYPE),
    ])
    stub.__headers__.put_nowait([
        ('grpc-status', str(Status.OK.value)),
    ])
    header, data = encode_message(SavoysReply(benito='giselle'))
    stub.__data__.put_nowait(header)
    stub.__data__.put_nowait(data)
    async with stream:
        await stream.send_message(SavoysRequest(kyler='bhatta'), end=True)
        assert await stream.recv_message() == SavoysReply(benito='giselle')
Ejemplo n.º 7
0
async def test_unary_unary(stub):
    async with stub.stream:
        await stub.stream.send_message(SavoysRequest(kyler='bhatta'), end=True)

        events = stub.server.events()
        stream_id = events[-1].stream_id

        stub.server.connection.send_headers(
            stream_id,
            [(':status', '200'), ('content-type', CONTENT_TYPE)],
        )
        stub.server.connection.send_data(
            stream_id,
            encode_message(SavoysReply(benito='giselle')),
        )
        stub.server.connection.send_headers(
            stream_id,
            [('grpc-status', str(Status.OK.value))],
            end_stream=True,
        )
        stub.server.flush()

        assert await stub.stream.recv_message() == \
            SavoysReply(benito='giselle')
Ejemplo n.º 8
0
 async def worker2():
     s2 = Stream(stub.channel, request, SavoysRequest, SavoysReply)
     async with s2:
         await s2.send_message(SavoysRequest(kyler='bhatta'), end=True)
         assert await s2.recv_message() == SavoysReply(benito='giselle')
Ejemplo n.º 9
0
async def test_unary_unary_simple(loop):
    async with ClientServer(loop=loop) as (handler, stub):
        reply = await stub.Plaster(SavoysRequest(kyler='huizhou'))
        assert reply == SavoysReply(benito='bebops')
        assert handler.log == [SavoysRequest(kyler='huizhou')]