Beispiel #1
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')
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')
Beispiel #3
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')]
Beispiel #4
0
async def test_error_after_send_trailing_metadata(stream, stub):
    async with stream:
        await stream.send_message(SavoysReply(benito='aimee'))
        await stream.send_trailing_metadata()
        raise Exception()
    assert stub.__events__ == [
        SendHeaders(
            [(':status', '200'), ('content-type', CONTENT_TYPE)],
            end_stream=False,
        ),
        SendData(
            encode_message(SavoysReply(benito='aimee')),
            end_stream=False,
        ),
        SendHeaders(
            [('grpc-status', str(Status.OK.value))],
            end_stream=True,
        ),
    ]
Beispiel #5
0
async def test_stream_unary_advanced(loop):
    async with ClientServer(loop=loop) as (handler, stub):
        async with stub.Anginal.open() as stream:
            await stream.send_message(UnyoungChunk(whome='canopy'))
            await stream.send_message(UnyoungChunk(whome='iver'))
            await stream.send_message(UnyoungChunk(whome='part'), end=True)
            reply = await stream.recv_message()
        assert reply == SavoysReply(benito='anagogy')
        assert handler.log == [UnyoungChunk(whome='canopy'),
                               UnyoungChunk(whome='iver'),
                               UnyoungChunk(whome='part')]
Beispiel #6
0
async def test_stream_unary_simple(loop):
    async with ClientServer(loop=loop) as (handler, stub):
        reply = await stub.Anginal([
            UnyoungChunk(whome='canopy'),
            UnyoungChunk(whome='iver'),
            UnyoungChunk(whome='part'),
        ])
        assert reply == SavoysReply(benito='anagogy')
        assert handler.log == [UnyoungChunk(whome='canopy'),
                               UnyoungChunk(whome='iver'),
                               UnyoungChunk(whome='part')]
Beispiel #7
0
async def test_send_message_twice_ok(stream_streaming, stub):
    async with stream_streaming:
        await stream_streaming.send_message(SavoysReply(benito='aimee'))
        await stream_streaming.send_message(SavoysReply(benito='amaya'))
    assert stub.__events__ == [
        SendHeaders(
            [(':status', '200'), ('content-type', CONTENT_TYPE)],
            end_stream=False,
        ),
        SendData(
            encode_message(SavoysReply(benito='aimee')),
            end_stream=False,
        ),
        SendData(
            encode_message(SavoysReply(benito='amaya')),
            end_stream=False,
        ),
        SendHeaders(
            [('grpc-status', str(Status.OK.value))],
            end_stream=True,
        ),
    ]
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')
 def send_response(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()
Beispiel #10
0
async def test_send_message_twice(stream):
    async with stream:
        await stream.send_message(SavoysReply(benito='aimee'))
        with pytest.raises(ProtocolError) as err:
            await stream.send_message(SavoysReply(benito='amaya'))
    err.match('Server should send exactly one message in response')
 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')
Beispiel #12
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')]
Beispiel #13
0
 async def Anginal(self, stream):
     async for request in stream:
         self.log.append(request)
     await stream.send_message(SavoysReply(benito='anagogy'))
Beispiel #14
0
 async def Plaster(self, stream):
     request = await stream.recv_message()
     self.log.append(request)
     await stream.send_message(SavoysReply(benito='bebops'))