Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Pick up fixes in GAPIC generator. (#6489)
Browse files Browse the repository at this point in the history
Includes fixes from these `gapic-generator` PRs:

- googleapis/gapic-generator#2407
- googleapis/gapic-generator#2396
  • Loading branch information
yoshi-automation authored and tseaver committed Nov 14, 2018
1 parent c9f692e commit a60ed8f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
17 changes: 12 additions & 5 deletions google/cloud/asset_v1beta1/gapic/asset_service_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions google/cloud/asset_v1beta1/gapic/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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}.
Expand Down
21 changes: 17 additions & 4 deletions tests/unit/gapic/v1beta1/test_asset_service_client_v1beta1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# limitations under the License.
"""Unit tests."""

import mock
import pytest

from google.rpc import status_pb2
Expand Down Expand Up @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand All @@ -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]')
Expand Down

0 comments on commit a60ed8f

Please sign in to comment.