示例#1
0
async def test_helloworld_sayhelloslowly(asgi_greeter):
    for name in ("you", "world"):
        request = helloworld_pb2.HelloRequest(name=name)
        response = asgi_greeter.SayHelloSlowly(request)
        message = "".join([r.message async for r in response])
        assert message != name
        assert name in message
示例#2
0
async def test_helloworld_unary_metadata_ascii(asgi_greeter):
    request = helloworld_pb2.HelloRequest(name="metadata-key")
    call = asgi_greeter.HelloMetadata(request, metadata=[("metadata-key", "honk")])
    result = await call
    assert repr("honk") == result.message

    initial_metadata = await call.initial_metadata()
    trailing_metadata = await call.trailing_metadata()

    assert dict(initial_metadata)["initial-metadata-key"] == repr("honk")
    assert dict(trailing_metadata)["trailing-metadata-key"] == repr("honk")
示例#3
0
async def test_helloworld_sayhelloslowly_read(asgi_greeter):
    for name in ("you", "world"):
        request = helloworld_pb2.HelloRequest(name=name)
        message = ""
        with asgi_greeter.SayHelloSlowly(request) as stream:
            chunk = await stream.read()
            while chunk:
                message += chunk.message
                chunk = await stream.read()
        assert message != name
        assert name in message
示例#4
0
文件: test_aio.py 项目: public/sonora
async def test_helloworld_streamtimeout(asgi_greeter):
    request = helloworld_pb2.HelloRequest(name="client timeout")

    with pytest.raises(grpc.RpcError) as exc:
        with asgi_greeter.StreamTimeout(request, timeout=0) as call:
            response = await call.read()

            while response:
                await call.read()

    assert exc.value.code() == grpc.StatusCode.DEADLINE_EXCEEDED
示例#5
0
def test_helloworld_unary_metadata_binary(wsgi_greeter):
    request = helloworld_pb2.HelloRequest(name="metadata-key-bin")
    result, call = wsgi_greeter.HelloMetadata.with_call(
        request, metadata=[("metadata-key-bin", b"\0\1\2\3")])
    assert repr(b"\0\1\2\3") == result.message

    initial_metadata = call.initial_metadata()
    trailing_metadata = call.trailing_metadata()

    assert dict(initial_metadata)["initial-metadata-key-bin"] == repr(
        b"\0\1\2\3")
    assert dict(trailing_metadata)["trailing-metadata-key-bin"] == repr(
        b"\0\1\2\3")
示例#6
0
async def test_helloworld_stream_metadata_ascii(asgi_greeter):
    request = helloworld_pb2.HelloRequest(name="metadata-key")
    result = asgi_greeter.HelloStreamMetadata(
        request, metadata=[("metadata-key", "honk")]
    )

    message = "".join([m.message async for m in result])

    assert "honk" == message

    initial_metadata = await result.initial_metadata()
    trailing_metadata = await result.trailing_metadata()

    assert dict(initial_metadata)["initial-metadata-key"] == repr("honk")
    assert dict(trailing_metadata)["trailing-metadata-key"] == repr("honk")
示例#7
0
def test_helloworld_stream_metadata_ascii(wsgi_greeter):
    request = helloworld_pb2.HelloRequest(name="metadata-key")
    result = wsgi_greeter.HelloStreamMetadata(request,
                                              metadata=[("metadata-key",
                                                         "honk")])

    message = "".join(m.message for m in result)

    assert "honk" == message

    initial_metadata = result.initial_metadata()
    trailing_metadata = result.trailing_metadata()
    print("initial_metadata", initial_metadata)
    print("trailing_metadata", trailing_metadata)
    assert dict(initial_metadata)["initial-metadata-key"] == repr("honk")
    assert dict(trailing_metadata)["trailing-metadata-key"] == repr("honk")
示例#8
0
文件: test_aio.py 项目: public/sonora
async def test_helloworld_sayhelloslowly_with(asgi_greeter_server):
    async with sonora.aio.insecure_web_channel(
            f"http://localhost:{asgi_greeter_server}") as channel:
        stub = helloworld_pb2_grpc.GreeterStub(channel)

        for name in ("you", "world"):
            buffer = []

            request = helloworld_pb2.HelloRequest(name=name)

            with stub.SayHelloSlowly(request) as call:
                response = await call.read()

                while response:
                    buffer.append(response.message)
                    response = await call.read()

            message = "".join(buffer)
            assert message != name
            assert name in message
示例#9
0
async def test_helloworld_sayhello(asgi_greeter):
    for name in ("you", "world"):
        request = helloworld_pb2.HelloRequest(name=name)
        response = await asgi_greeter.SayHello(request)
        assert response.message != name
        assert name in response.message
示例#10
0
文件: test_aio.py 项目: public/sonora
async def test_helloworld_unarytimeout(asgi_greeter):
    request = helloworld_pb2.HelloRequest(name="client timeout")
    with pytest.raises(grpc.RpcError) as exc:
        await asgi_greeter.UnaryTimeout(request, timeout=0)
    assert exc.value.code() == grpc.StatusCode.DEADLINE_EXCEEDED