Skip to content

Commit

Permalink
GAPIC Header Consistency: Pubsub (#3052)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer authored Feb 23, 2017
1 parent ab1ce15 commit dae40f9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
11 changes: 7 additions & 4 deletions pubsub/google/cloud/pubsub/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions pubsub/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down
48 changes: 37 additions & 11 deletions pubsub/unit_tests/test__gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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])

Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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])

Expand Down

0 comments on commit dae40f9

Please sign in to comment.