From 8165cc2d9702cac002d8b0cf4f7d242d22812629 Mon Sep 17 00:00:00 2001 From: Mariano Anaya Date: Fri, 14 Feb 2020 17:13:26 +0100 Subject: [PATCH] Extend with more tests --- src/python/grpcio_tests/tests_aio/tests.json | 1 + .../tests_aio/unit/secure_call_test.py | 37 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio_tests/tests_aio/tests.json b/src/python/grpcio_tests/tests_aio/tests.json index ace685d169f..2aae8533b96 100644 --- a/src/python/grpcio_tests/tests_aio/tests.json +++ b/src/python/grpcio_tests/tests_aio/tests.json @@ -23,6 +23,7 @@ "unit.interceptor_test.TestInterceptedUnaryUnaryCall", "unit.interceptor_test.TestUnaryUnaryClientInterceptor", "unit.metadata_test.TestMetadata", + "unit.secure_call_test.TestUnaryStreamSecureCall", "unit.secure_call_test.TestUnaryUnarySecureCall", "unit.server_test.TestServer", "unit.timeout_test.TestTimeout", diff --git a/src/python/grpcio_tests/tests_aio/unit/secure_call_test.py b/src/python/grpcio_tests/tests_aio/unit/secure_call_test.py index cff870c3054..038a684f509 100644 --- a/src/python/grpcio_tests/tests_aio/unit/secure_call_test.py +++ b/src/python/grpcio_tests/tests_aio/unit/secure_call_test.py @@ -9,6 +9,8 @@ from tests_aio.unit._test_server import start_test_server from tests.unit import resources _SERVER_HOST_OVERRIDE = 'foo.test.google.fr' +_NUM_STREAM_RESPONSES = 5 +_RESPONSE_PAYLOAD_SIZE = 42 class _SecureCallMixin: @@ -37,14 +39,45 @@ class _SecureCallMixin: class TestUnaryUnarySecureCall(_SecureCallMixin, AioTestBase): - """Calls made over a secure channel.""" + """unary_unary Calls made over a secure channel.""" - async def test_call_ok_with_credentials(self): + async def test_call_ok_over_secure_channel(self): call = self._stub.UnaryCall(messages_pb2.SimpleRequest()) response = await call self.assertIsInstance(response, messages_pb2.SimpleResponse) self.assertEqual(await call.code(), grpc.StatusCode.OK) + async def test_call_with_credentials(self): + call_credentials = grpc.composite_call_credentials( + grpc.access_token_call_credentials("abc"), + grpc.access_token_call_credentials("def"), + ) + call = self._stub.UnaryCall(messages_pb2.SimpleRequest(), credentials=call_credentials) + response = await call + + self.assertIsInstance(response, messages_pb2.SimpleResponse) + + +class TestUnaryStreamSecureCall(_SecureCallMixin, AioTestBase): + """unary_stream calls over a secure channel""" + + async def test_unary_stream_async_generator_credentials(self): + request = messages_pb2.StreamingOutputCallRequest() + request.response_parameters.extend( + messages_pb2.ResponseParameters(size=_RESPONSE_PAYLOAD_SIZE,) + for _ in range(_NUM_STREAM_RESPONSES) + ) + call = self._stub.StreamingOutputCall(request) + + async for response in call: + self.assertIsInstance( + response, + messages_pb2.StreamingOutputCallResponse + ) + self.assertEqual(len(response.payload.body), _RESPONSE_PAYLOAD_SIZE) + + self.assertEqual(await call.code(), grpc.StatusCode.OK) + if __name__ == '__main__': logging.basicConfig()