def test_echo(transport: str = 'grpc'):
    client = EchoClient(
        credentials=credentials.AnonymousCredentials(),
        transport=transport,
    )

    # Everything is optional in proto3 as far as the runtime is concerned,
    # and we are mocking out the actual API, so just send an empty request.
    request = gs_echo.EchoRequest()

    # Mock the actual call within the gRPC stub, and fake the request.
    with mock.patch.object(type(client._transport.echo), '__call__') as call:
        # Designate an appropriate return value for the call.
        call.return_value = gs_echo.EchoResponse(content='content_value', )

        response = client.echo(request)

        # Establish that the underlying gRPC stub method was called.
        assert len(call.mock_calls) == 1
        _, args, _ = call.mock_calls[0]

        assert args[0] == request

    # Establish that the response is the type that we expect.
    assert isinstance(response, gs_echo.EchoResponse)
    assert response.content == 'content_value'
Ejemplo n.º 2
0
def test_echo():
  print("=================test echo ===================")
  client = EchoClient(transport=transport)
  request = gs_echo.EchoRequest(content='hello world')
  response = client.echo(request)
  print(response)