Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pubsub: pick up fixes to GAPIC generator. #6503

Merged
merged 1 commit into from
Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pubsub/google/cloud/pubsub_v1/gapic/publisher_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=publisher_client_config.config,
client_config=None,
client_info=None):
"""Constructor.

Expand Down Expand Up @@ -136,13 +136,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 = publisher_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
17 changes: 12 additions & 5 deletions pubsub/google/cloud/pubsub_v1/gapic/subscriber_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __init__(self,
transport=None,
channel=None,
credentials=None,
client_config=subscriber_client_config.config,
client_config=None,
client_info=None):
"""Constructor.

Expand Down Expand Up @@ -157,13 +157,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 = subscriber_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
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 @@ -96,6 +98,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 create_topic(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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 @@ -96,6 +98,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 create_subscription(self):
"""Return the gRPC stub for {$apiMethod.name}.
Expand Down
101 changes: 81 additions & 20 deletions pubsub/tests/unit/gapic/v1/test_publisher_client_v1.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.cloud.pubsub_v1.gapic import publisher_client
Expand Down Expand Up @@ -73,7 +74,10 @@ def test_create_topic(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
name = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -89,7 +93,10 @@ def test_create_topic(self):
def test_create_topic_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
name = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -105,7 +112,10 @@ def test_update_topic(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
topic = {}
Expand All @@ -123,7 +133,10 @@ def test_update_topic(self):
def test_update_topic_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
topic = {}
Expand All @@ -141,7 +154,10 @@ def test_publish(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
topic = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -161,7 +177,10 @@ def test_publish(self):
def test_publish_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
topic = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -180,7 +199,10 @@ def test_get_topic(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
topic = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -196,7 +218,10 @@ def test_get_topic(self):
def test_get_topic_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
topic = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -217,7 +242,10 @@ def test_list_topics(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
project = client.project_path('[PROJECT]')
Expand All @@ -235,7 +263,10 @@ def test_list_topics(self):

def test_list_topics_exception(self):
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
project = client.project_path('[PROJECT]')
Expand All @@ -258,7 +289,10 @@ def test_list_topic_subscriptions(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
topic = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -277,7 +311,10 @@ def test_list_topic_subscriptions(self):

def test_list_topic_subscriptions_exception(self):
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
topic = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -288,7 +325,10 @@ def test_list_topic_subscriptions_exception(self):

def test_delete_topic(self):
channel = ChannelStub()
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
topic = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -303,7 +343,10 @@ def test_delete_topic(self):
def test_delete_topic_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
topic = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -320,7 +363,10 @@ def test_set_iam_policy(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
resource = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -338,7 +384,10 @@ def test_set_iam_policy(self):
def test_set_iam_policy_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
resource = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -356,7 +405,10 @@ def test_get_iam_policy(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
resource = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -373,7 +425,10 @@ def test_get_iam_policy(self):
def test_get_iam_policy_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
resource = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -389,7 +444,10 @@ def test_test_iam_permissions(self):

# Mock the API response
channel = ChannelStub(responses=[expected_response])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup Request
resource = client.topic_path('[PROJECT]', '[TOPIC]')
Expand All @@ -407,7 +465,10 @@ def test_test_iam_permissions(self):
def test_test_iam_permissions_exception(self):
# Mock the API response
channel = ChannelStub(responses=[CustomException()])
client = publisher_client.PublisherClient(channel=channel)
patch = mock.patch('google.api_core.grpc_helpers.create_channel')
with patch as create_channel:
create_channel.return_value = channel
client = publisher_client.PublisherClient()

# Setup request
resource = client.topic_path('[PROJECT]', '[TOPIC]')
Expand Down
Loading