diff --git a/pubsub/google/cloud/pubsub/_gax.py b/pubsub/google/cloud/pubsub/_gax.py index 582cb8d0e128..17c93786c442 100644 --- a/pubsub/google/cloud/pubsub/_gax.py +++ b/pubsub/google/cloud/pubsub/_gax.py @@ -23,8 +23,8 @@ from google.gax.errors import GaxError from google.gax.grpc import exc_to_code from google.protobuf.json_format import MessageToDict -from google.cloud.grpc.pubsub.v1.pubsub_pb2 import PubsubMessage -from google.cloud.grpc.pubsub.v1.pubsub_pb2 import PushConfig +from google.cloud.proto.pubsub.v1.pubsub_pb2 import PubsubMessage +from google.cloud.proto.pubsub.v1.pubsub_pb2 import PushConfig from grpc import insecure_channel from grpc import StatusCode @@ -35,6 +35,7 @@ from google.cloud.exceptions import Conflict from google.cloud.exceptions import NotFound from google.cloud.iterator import GAXIterator +from google.cloud.pubsub import __version__ from google.cloud.pubsub._helpers import subscription_name_from_path from google.cloud.pubsub.subscription import Subscription from google.cloud.pubsub.topic import Topic @@ -535,7 +536,8 @@ def make_gax_publisher_api(credentials=None, host=None): channel = make_secure_channel( credentials, DEFAULT_USER_AGENT, PublisherClient.SERVICE_ADDRESS) - return PublisherClient(channel=channel) + return PublisherClient( + channel=channel, lib_name='gccl', lib_version=__version__) def make_gax_subscriber_api(credentials=None, host=None): @@ -561,7 +563,8 @@ def make_gax_subscriber_api(credentials=None, host=None): channel = make_secure_channel( credentials, DEFAULT_USER_AGENT, SubscriberClient.SERVICE_ADDRESS) - return SubscriberClient(channel=channel) + return SubscriberClient( + channel=channel, lib_name='gccl', lib_version=__version__) def _item_to_topic(iterator, resource): diff --git a/pubsub/setup.py b/pubsub/setup.py index 6976796efeaf..2c69849b3708 100644 --- a/pubsub/setup.py +++ b/pubsub/setup.py @@ -52,12 +52,12 @@ REQUIREMENTS = [ 'google-cloud-core >= 0.23.0, < 0.24dev', 'grpcio >= 1.0.2, < 2.0dev', - 'gapic-google-cloud-pubsub-v1 >= 0.14.0, < 0.15dev', + 'gapic-google-cloud-pubsub-v1 >= 0.15.0, < 0.16dev', ] setup( name='google-cloud-pubsub', - version='0.22.0', + version='0.23.0', description='Python Client for Google Cloud Pub/Sub', long_description=README, namespace_packages=[ diff --git a/pubsub/unit_tests/test__gax.py b/pubsub/unit_tests/test__gax.py index cb3bb0ee7c07..95f908f0c3f4 100644 --- a/pubsub/unit_tests/test__gax.py +++ b/pubsub/unit_tests/test__gax.py @@ -436,8 +436,8 @@ def test_ctor(self): def test_list_subscriptions_no_paging(self): from google.gax import INITIAL_PAGE - from google.cloud.grpc.pubsub.v1.pubsub_pb2 import PushConfig - from google.cloud.grpc.pubsub.v1.pubsub_pb2 import ( + from google.cloud.proto.pubsub.v1.pubsub_pb2 import PushConfig + from google.cloud.proto.pubsub.v1.pubsub_pb2 import ( Subscription as SubscriptionPB) from google.cloud._testing import _GAXPageIterator from google.cloud.pubsub.client import Client @@ -479,8 +479,8 @@ def test_list_subscriptions_no_paging(self): self.assertIs(options.page_token, INITIAL_PAGE) def test_list_subscriptions_with_paging(self): - from google.cloud.grpc.pubsub.v1.pubsub_pb2 import PushConfig - from google.cloud.grpc.pubsub.v1.pubsub_pb2 import ( + from google.cloud.proto.pubsub.v1.pubsub_pb2 import PushConfig + from google.cloud.proto.pubsub.v1.pubsub_pb2 import ( Subscription as SubscriptionPB) from google.cloud._testing import _GAXPageIterator from google.cloud.pubsub.client import Client @@ -527,7 +527,7 @@ def test_list_subscriptions_with_paging(self): self.assertEqual(options.page_token, TOKEN) def test_subscription_create(self): - from google.cloud.grpc.pubsub.v1.pubsub_pb2 import Subscription + from google.cloud.proto.pubsub.v1.pubsub_pb2 import Subscription sub_pb = Subscription(name=self.SUB_PATH, topic=self.TOPIC_PATH) gax_api = _GAXSubscriberAPI(_create_subscription_response=sub_pb) @@ -588,8 +588,8 @@ def test_subscription_create_error(self): self.assertIsNone(options) def test_subscription_get_hit(self): - from google.cloud.grpc.pubsub.v1.pubsub_pb2 import PushConfig - from google.cloud.grpc.pubsub.v1.pubsub_pb2 import Subscription + from google.cloud.proto.pubsub.v1.pubsub_pb2 import PushConfig + from google.cloud.proto.pubsub.v1.pubsub_pb2 import Subscription push_cfg_pb = PushConfig(push_endpoint=self.PUSH_ENDPOINT) sub_pb = Subscription(name=self.SUB_PATH, topic=self.TOPIC_PATH, @@ -932,16 +932,19 @@ def _call_fut(self, *args, **kwargs): return make_gax_publisher_api(*args, **kwargs) def test_live_api(self): + from google.cloud.pubsub import __version__ from google.cloud.pubsub._gax import DEFAULT_USER_AGENT channels = [] + publisher_api_kwargs = [] channel_args = [] channel_obj = object() mock_result = object() host = 'foo.apis.invalid' - def mock_publisher_api(channel): + def mock_publisher_api(channel, **kwargs): channels.append(channel) + publisher_api_kwargs.append(kwargs) return mock_result def make_channel(*args): @@ -959,18 +962,25 @@ def make_channel(*args): result = self._call_fut(creds) self.assertIs(result, mock_result) + self.assertEqual(len(publisher_api_kwargs), 1) + self.assertEqual(publisher_api_kwargs[0]['lib_name'], 'gccl') + self.assertEqual(publisher_api_kwargs[0]['lib_version'], __version__) self.assertEqual(channels, [channel_obj]) self.assertEqual(channel_args, [(creds, DEFAULT_USER_AGENT, host)]) def test_emulator(self): + from google.cloud.pubsub import __version__ + channels = [] + publisher_api_kwargs = [] mock_result = object() insecure_args = [] mock_channel = object() - def mock_publisher_api(channel): + def mock_publisher_api(channel, **kwargs): channels.append(channel) + publisher_api_kwargs.append(kwargs) return mock_result def mock_insecure_channel(host): @@ -986,6 +996,9 @@ def mock_insecure_channel(host): result = self._call_fut(host=host) self.assertIs(result, mock_result) + self.assertEqual(len(publisher_api_kwargs), 1) + self.assertEqual(publisher_api_kwargs[0]['lib_name'], 'gccl') + self.assertEqual(publisher_api_kwargs[0]['lib_version'], __version__) self.assertEqual(channels, [mock_channel]) self.assertEqual(insecure_args, [host]) @@ -999,16 +1012,19 @@ def _call_fut(self, *args, **kwargs): return make_gax_subscriber_api(*args, **kwargs) def test_live_api(self): + from google.cloud.pubsub import __version__ from google.cloud.pubsub._gax import DEFAULT_USER_AGENT channels = [] + subscriber_api_kwargs = [] channel_args = [] channel_obj = object() mock_result = object() host = 'foo.apis.invalid' - def mock_subscriber_api(channel): + def mock_subscriber_api(channel, **kwargs): channels.append(channel) + subscriber_api_kwargs.append(kwargs) return mock_result def make_channel(*args): @@ -1026,18 +1042,25 @@ def make_channel(*args): result = self._call_fut(creds) self.assertIs(result, mock_result) + self.assertEqual(len(subscriber_api_kwargs), 1) + self.assertEqual(subscriber_api_kwargs[0]['lib_name'], 'gccl') + self.assertEqual(subscriber_api_kwargs[0]['lib_version'], __version__) self.assertEqual(channels, [channel_obj]) self.assertEqual(channel_args, [(creds, DEFAULT_USER_AGENT, host)]) def test_emulator(self): + from google.cloud.pubsub import __version__ + channels = [] + subscriber_api_kwargs = [] mock_result = object() insecure_args = [] mock_channel = object() - def mock_subscriber_api(channel): + def mock_subscriber_api(channel, **kwargs): channels.append(channel) + subscriber_api_kwargs.append(kwargs) return mock_result def mock_insecure_channel(host): @@ -1053,6 +1076,9 @@ def mock_insecure_channel(host): result = self._call_fut(host=host) self.assertIs(result, mock_result) + self.assertEqual(len(subscriber_api_kwargs), 1) + self.assertEqual(subscriber_api_kwargs[0]['lib_name'], 'gccl') + self.assertEqual(subscriber_api_kwargs[0]['lib_version'], __version__) self.assertEqual(channels, [mock_channel]) self.assertEqual(insecure_args, [host])