From 943b283a50e56eed1a81c85b574898daf0c19e38 Mon Sep 17 00:00:00 2001 From: dpcollins-google <40498610+dpcollins-google@users.noreply.github.com> Date: Wed, 23 Dec 2020 10:47:46 -0500 Subject: [PATCH 1/2] fix: Update gapic-generator-python to gracefully handle internal google inconsistencies --- .../unit/gapic/%name_%version/%sub/test_%service.py.j2 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index 570e997a6f..bb2cc84573 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -5,6 +5,7 @@ import os import mock import grpc +from grpc import local_credentials from grpc.experimental import aio import math import pytest @@ -1186,7 +1187,7 @@ def test_{{ service.name|snake_case }}_host_with_port(): def test_{{ service.name|snake_case }}_grpc_transport_channel(): - channel = grpc.insecure_channel('http://localhost/') + channel = grpc.secure_channel('http://localhost/', local_credentials.local_channel_credentials()) # Check that channel is used if provided. transport = transports.{{ service.name }}GrpcTransport( @@ -1199,7 +1200,7 @@ def test_{{ service.name|snake_case }}_grpc_transport_channel(): def test_{{ service.name|snake_case }}_grpc_asyncio_transport_channel(): - channel = aio.insecure_channel('http://localhost/') + channel = aio.secure_channel('http://localhost/', local_credentials.local_channel_credentials()) # Check that channel is used if provided. transport = transports.{{ service.name }}GrpcAsyncIOTransport( @@ -1216,7 +1217,7 @@ def test_{{ service.name|snake_case }}_transport_channel_mtls_with_client_cert_s transport_class ): with mock.patch("grpc.ssl_channel_credentials", autospec=True) as grpc_ssl_channel_cred: - with mock.patch.object(transport_class, "create_channel", autospec=True) as grpc_create_channel: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: mock_ssl_cred = mock.Mock() grpc_ssl_channel_cred.return_value = mock_ssl_cred @@ -1267,7 +1268,7 @@ def test_{{ service.name|snake_case }}_transport_channel_mtls_with_adc( __init__=mock.Mock(return_value=None), ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), ): - with mock.patch.object(transport_class, "create_channel", autospec=True) as grpc_create_channel: + with mock.patch.object(transport_class, "create_channel") as grpc_create_channel: mock_grpc_channel = mock.Mock() grpc_create_channel.return_value = mock_grpc_channel mock_cred = mock.Mock() From d8c16d6f04b329ea0dbfd6571fb16260d6fcc5b0 Mon Sep 17 00:00:00 2001 From: dpcollins-google <40498610+dpcollins-google@users.noreply.github.com> Date: Wed, 23 Dec 2020 10:52:10 -0500 Subject: [PATCH 2/2] fix: wrong name for local_channel_credentials --- .../tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index bb2cc84573..b2f8ef8c0d 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -5,7 +5,6 @@ import os import mock import grpc -from grpc import local_credentials from grpc.experimental import aio import math import pytest @@ -1187,7 +1186,7 @@ def test_{{ service.name|snake_case }}_host_with_port(): def test_{{ service.name|snake_case }}_grpc_transport_channel(): - channel = grpc.secure_channel('http://localhost/', local_credentials.local_channel_credentials()) + channel = grpc.secure_channel('http://localhost/', grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.{{ service.name }}GrpcTransport( @@ -1200,7 +1199,7 @@ def test_{{ service.name|snake_case }}_grpc_transport_channel(): def test_{{ service.name|snake_case }}_grpc_asyncio_transport_channel(): - channel = aio.secure_channel('http://localhost/', local_credentials.local_channel_credentials()) + channel = aio.secure_channel('http://localhost/', grpc.local_channel_credentials()) # Check that channel is used if provided. transport = transports.{{ service.name }}GrpcAsyncIOTransport(