Skip to content

Commit

Permalink
Merge pull request #1798 from tseaver/pubsub-gax_fix_subscription_mar…
Browse files Browse the repository at this point in the history
…shalling

Fix Gax marshalling of Subscription protobufs.
  • Loading branch information
tseaver committed May 16, 2016
2 parents bb26745 + 73d5783 commit 755bf52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions gcloud/pubsub/_gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,11 @@ def _subscription_pb_to_mapping(sub_pb):
mapping = {
'name': sub_pb.name,
'topic': sub_pb.topic,
'ack_deadline': sub_pb.ack_deadline,
'ackDeadlineSeconds': sub_pb.ack_deadline_seconds,
}
if sub_pb.push_config.push_endpoint != '':
mapping['push_config'] = {
'push_endpoint': sub_pb.push_config.push_endpoint,
mapping['pushConfig'] = {
'pushEndpoint': sub_pb.push_config.push_endpoint,
}
return mapping

Expand Down
20 changes: 12 additions & 8 deletions gcloud/pubsub/test__gax.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,9 @@ def test_list_subscriptions_no_paging(self):
self.assertIsInstance(subscription, dict)
self.assertEqual(subscription['name'], self.SUB_PATH)
self.assertEqual(subscription['topic'], self.TOPIC_PATH)
self.assertEqual(subscription['push_config'],
{'push_endpoint': self.PUSH_ENDPOINT})
self.assertEqual(subscription['ack_deadline'], 0)
self.assertEqual(subscription['pushConfig'],
{'pushEndpoint': self.PUSH_ENDPOINT})
self.assertEqual(subscription['ackDeadlineSeconds'], 0)
self.assertEqual(next_token, None)

name, options = gax_api._list_subscriptions_called_with
Expand All @@ -322,7 +322,7 @@ def test_subscription_create(self):
expected = {
'name': self.SUB_PATH,
'topic': self.TOPIC_PATH,
'ack_deadline': 0,
'ackDeadlineSeconds': 0,
}
self.assertEqual(resource, expected)
name, topic, push_config, ack_deadline, options = (
Expand Down Expand Up @@ -368,7 +368,8 @@ def test_subscription_create_error(self):
self.assertEqual(options, None)

def test_subscription_get_hit(self):
sub_pb = _SubscriptionPB(self.SUB_PATH, self.TOPIC_PATH, '', 0)
sub_pb = _SubscriptionPB(
self.SUB_PATH, self.TOPIC_PATH, self.PUSH_ENDPOINT, 0)
gax_api = _GAXSubscriberAPI(_get_subscription_response=sub_pb)
api = self._makeOne(gax_api)

Expand All @@ -377,7 +378,10 @@ def test_subscription_get_hit(self):
expected = {
'name': self.SUB_PATH,
'topic': self.TOPIC_PATH,
'ack_deadline': 0,
'ackDeadlineSeconds': 0,
'pushConfig': {
'pushEndpoint': self.PUSH_ENDPOINT,
},
}
self.assertEqual(resource, expected)
sub_path, options = gax_api._get_subscription_called_with
Expand Down Expand Up @@ -851,11 +855,11 @@ def __init__(self, received_messages):

class _SubscriptionPB(object):

def __init__(self, name, topic, push_endpoint, ack_deadline):
def __init__(self, name, topic, push_endpoint, ack_deadline_seconds):
self.name = name
self.topic = topic
self.push_config = _PushConfigPB(push_endpoint)
self.ack_deadline = ack_deadline
self.ack_deadline_seconds = ack_deadline_seconds


class _ListSubscriptionsResponsePB(object):
Expand Down

0 comments on commit 755bf52

Please sign in to comment.