From 4523af4ebd9c27335a87f809082be3b180b55700 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Mon, 19 Nov 2018 11:28:14 -0500 Subject: [PATCH] Pick up fixes to GAPIC generator. (#6575) Includes fixes from these PRs: - googleapis/gapic-generator#2407 (closing googleapis/gapic-generator#2389) - googleapis/gapic-generator#2396 (for #5523 and dupes). Includes changes to generated tests. Closes #6502. --- .../gapic/os_login_service_client.py | 17 +++-- .../os_login_service_grpc_transport.py | 11 ++++ oslogin/synth.py | 1 + .../v1/test_os_login_service_client_v1.py | 63 +++++++++++++++---- 4 files changed, 75 insertions(+), 17 deletions(-) diff --git a/oslogin/google/cloud/oslogin_v1/gapic/os_login_service_client.py b/oslogin/google/cloud/oslogin_v1/gapic/os_login_service_client.py index b04fbc5aadda..46836f5b176b 100644 --- a/oslogin/google/cloud/oslogin_v1/gapic/os_login_service_client.py +++ b/oslogin/google/cloud/oslogin_v1/gapic/os_login_service_client.py @@ -104,7 +104,7 @@ def __init__(self, transport=None, channel=None, credentials=None, - client_config=os_login_service_client_config.config, + client_config=None, client_info=None): """Constructor. @@ -137,13 +137,20 @@ def __init__(self, your own client library. """ # Raise deprecation warnings for things we want to go away. - if client_config: - warnings.warn('The `client_config` argument is deprecated.', - PendingDeprecationWarning) + if client_config is not None: + warnings.warn( + 'The `client_config` argument is deprecated.', + PendingDeprecationWarning, + stacklevel=2) + else: + client_config = os_login_service_client_config.config + if channel: warnings.warn( 'The `channel` argument is deprecated; use ' - '`transport` instead.', PendingDeprecationWarning) + '`transport` instead.', + PendingDeprecationWarning, + stacklevel=2) # Instantiate the transport. # The transport is responsible for handling serialization and diff --git a/oslogin/google/cloud/oslogin_v1/gapic/transports/os_login_service_grpc_transport.py b/oslogin/google/cloud/oslogin_v1/gapic/transports/os_login_service_grpc_transport.py index 83f75c1947e0..e3f5087daeb6 100644 --- a/oslogin/google/cloud/oslogin_v1/gapic/transports/os_login_service_grpc_transport.py +++ b/oslogin/google/cloud/oslogin_v1/gapic/transports/os_login_service_grpc_transport.py @@ -67,6 +67,8 @@ def __init__(self, credentials=credentials, ) + self._channel = channel + # gRPC uses objects called "stubs" that are bound to the # channel and provide a basic method for each RPC. self._stubs = { @@ -97,6 +99,15 @@ def create_channel(cls, scopes=cls._OAUTH_SCOPES, ) + @property + def channel(self): + """The gRPC channel used by the transport. + + Returns: + grpc.Channel: A gRPC channel object. + """ + return self._channel + @property def delete_posix_account(self): """Return the gRPC stub for {$apiMethod.name}. diff --git a/oslogin/synth.py b/oslogin/synth.py index ce95dca8c057..c58df694f14b 100644 --- a/oslogin/synth.py +++ b/oslogin/synth.py @@ -29,6 +29,7 @@ artman_output_name='os-login-v1') s.move(library / 'google/cloud/oslogin_v1') +s.move(library / 'tests/unit/gapic/v1') # Fix up imports s.replace( diff --git a/oslogin/tests/unit/gapic/v1/test_os_login_service_client_v1.py b/oslogin/tests/unit/gapic/v1/test_os_login_service_client_v1.py index 7eafd69309b6..adcc91446e52 100644 --- a/oslogin/tests/unit/gapic/v1/test_os_login_service_client_v1.py +++ b/oslogin/tests/unit/gapic/v1/test_os_login_service_client_v1.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright 2018 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -13,6 +15,7 @@ # limitations under the License. """Unit tests.""" +import mock import pytest from google.cloud import oslogin_v1 @@ -63,7 +66,10 @@ class CustomException(Exception): class TestOsLoginServiceClient(object): def test_delete_posix_account(self): channel = ChannelStub() - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup Request name = client.project_path('[USER]', '[PROJECT]') @@ -78,7 +84,10 @@ def test_delete_posix_account(self): def test_delete_posix_account_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup request name = client.project_path('[USER]', '[PROJECT]') @@ -88,7 +97,10 @@ def test_delete_posix_account_exception(self): def test_delete_ssh_public_key(self): channel = ChannelStub() - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup Request name = client.fingerprint_path('[USER]', '[FINGERPRINT]') @@ -103,7 +115,10 @@ def test_delete_ssh_public_key(self): def test_delete_ssh_public_key_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup request name = client.fingerprint_path('[USER]', '[FINGERPRINT]') @@ -120,7 +135,10 @@ def test_get_login_profile(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup Request name = client.user_path('[USER]') @@ -136,7 +154,10 @@ def test_get_login_profile(self): def test_get_login_profile_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup request name = client.user_path('[USER]') @@ -158,7 +179,10 @@ def test_get_ssh_public_key(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup Request name = client.fingerprint_path('[USER]', '[FINGERPRINT]') @@ -174,7 +198,10 @@ def test_get_ssh_public_key(self): def test_get_ssh_public_key_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup request name = client.fingerprint_path('[USER]', '[FINGERPRINT]') @@ -190,7 +217,10 @@ def test_import_ssh_public_key(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup Request parent = client.user_path('[USER]') @@ -208,7 +238,10 @@ def test_import_ssh_public_key(self): def test_import_ssh_public_key_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup request parent = client.user_path('[USER]') @@ -231,7 +264,10 @@ def test_update_ssh_public_key(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup Request name = client.fingerprint_path('[USER]', '[FINGERPRINT]') @@ -249,7 +285,10 @@ def test_update_ssh_public_key(self): def test_update_ssh_public_key_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = oslogin_v1.OsLoginServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = oslogin_v1.OsLoginServiceClient() # Setup request name = client.fingerprint_path('[USER]', '[FINGERPRINT]')