From a60ed8f27ce5eee1f09f0963d9a8eb39a41ded5e Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot <44816363+yoshi-automation@users.noreply.github.com> Date: Wed, 14 Nov 2018 10:13:53 -0800 Subject: [PATCH] Pick up fixes in GAPIC generator. (#6489) Includes fixes from these `gapic-generator` PRs: - https://github.com/googleapis/gapic-generator/pull/2407 - https://github.com/googleapis/gapic-generator/pull/2396 --- .../gapic/asset_service_client.py | 17 ++++++++---- google/cloud/asset_v1beta1/gapic/enums.py | 26 +++++++++---------- .../asset_service_grpc_transport.py | 11 ++++++++ .../test_asset_service_client_v1beta1.py | 21 ++++++++++++--- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/google/cloud/asset_v1beta1/gapic/asset_service_client.py b/google/cloud/asset_v1beta1/gapic/asset_service_client.py index 6b6fef9a..d3981eff 100644 --- a/google/cloud/asset_v1beta1/gapic/asset_service_client.py +++ b/google/cloud/asset_v1beta1/gapic/asset_service_client.py @@ -84,7 +84,7 @@ def __init__(self, transport=None, channel=None, credentials=None, - client_config=asset_service_client_config.config, + client_config=None, client_info=None): """Constructor. @@ -117,13 +117,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 = asset_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/google/cloud/asset_v1beta1/gapic/enums.py b/google/cloud/asset_v1beta1/gapic/enums.py index eaa86d48..b4cf3c0c 100644 --- a/google/cloud/asset_v1beta1/gapic/enums.py +++ b/google/cloud/asset_v1beta1/gapic/enums.py @@ -18,19 +18,6 @@ import enum -class NullValue(enum.IntEnum): - """ - ``NullValue`` is a singleton enumeration to represent the null value for - the ``Value`` type union. - - The JSON representation for ``NullValue`` is JSON ``null``. - - Attributes: - NULL_VALUE (int): Null value. - """ - NULL_VALUE = 0 - - class ContentType(enum.IntEnum): """ Asset content type. @@ -43,3 +30,16 @@ class ContentType(enum.IntEnum): CONTENT_TYPE_UNSPECIFIED = 0 RESOURCE = 1 IAM_POLICY = 2 + + +class NullValue(enum.IntEnum): + """ + ``NullValue`` is a singleton enumeration to represent the null value for + the ``Value`` type union. + + The JSON representation for ``NullValue`` is JSON ``null``. + + Attributes: + NULL_VALUE (int): Null value. + """ + NULL_VALUE = 0 diff --git a/google/cloud/asset_v1beta1/gapic/transports/asset_service_grpc_transport.py b/google/cloud/asset_v1beta1/gapic/transports/asset_service_grpc_transport.py index e1bed05f..b9cc8972 100644 --- a/google/cloud/asset_v1beta1/gapic/transports/asset_service_grpc_transport.py +++ b/google/cloud/asset_v1beta1/gapic/transports/asset_service_grpc_transport.py @@ -63,6 +63,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 = { @@ -99,6 +101,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 export_assets(self): """Return the gRPC stub for {$apiMethod.name}. diff --git a/tests/unit/gapic/v1beta1/test_asset_service_client_v1beta1.py b/tests/unit/gapic/v1beta1/test_asset_service_client_v1beta1.py index 1ab30f8f..4c2b65d1 100644 --- a/tests/unit/gapic/v1beta1/test_asset_service_client_v1beta1.py +++ b/tests/unit/gapic/v1beta1/test_asset_service_client_v1beta1.py @@ -15,6 +15,7 @@ # limitations under the License. """Unit tests.""" +import mock import pytest from google.rpc import status_pb2 @@ -77,7 +78,10 @@ def test_export_assets(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = asset_v1beta1.AssetServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = asset_v1beta1.AssetServiceClient() # Setup Request parent = client.project_path('[PROJECT]') @@ -102,7 +106,10 @@ def test_export_assets_exception(self): # Mock the API response channel = ChannelStub(responses=[operation]) - client = asset_v1beta1.AssetServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = asset_v1beta1.AssetServiceClient() # Setup Request parent = client.project_path('[PROJECT]') @@ -120,7 +127,10 @@ def test_batch_get_assets_history(self): # Mock the API response channel = ChannelStub(responses=[expected_response]) - client = asset_v1beta1.AssetServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = asset_v1beta1.AssetServiceClient() # Setup Request parent = client.project_path('[PROJECT]') @@ -142,7 +152,10 @@ def test_batch_get_assets_history(self): def test_batch_get_assets_history_exception(self): # Mock the API response channel = ChannelStub(responses=[CustomException()]) - client = asset_v1beta1.AssetServiceClient(channel=channel) + patch = mock.patch('google.api_core.grpc_helpers.create_channel') + with patch as create_channel: + create_channel.return_value = channel + client = asset_v1beta1.AssetServiceClient() # Setup request parent = client.project_path('[PROJECT]')