Skip to content
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
2 changes: 1 addition & 1 deletion gcloud/pubsub/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def pull(self, return_immediately=False, max_messages=1, connection=None):
path='%s:pull' % self.path,
data=data)
return [(info['ackId'], Message.from_api_repr(info['message']))
for info in response['receivedMessages']]
for info in response.get('receivedMessages', ())]

def acknowledge(self, ack_ids, connection=None):
"""API call: acknowledge retrieved messages for the subscription.
Expand Down
17 changes: 17 additions & 0 deletions gcloud/pubsub/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,23 @@ def test_pull_w_return_immediately_w_max_messages_w_explicit_conn(self):
self.assertEqual(req['data'],
{'returnImmediately': True, 'maxMessages': 3})

def test_pull_wo_receivedMessages(self):
PROJECT = 'PROJECT'
SUB_NAME = 'sub_name'
SUB_PATH = 'projects/%s/subscriptions/%s' % (PROJECT, SUB_NAME)
TOPIC_NAME = 'topic_name'
conn = _Connection({})
topic = _Topic(TOPIC_NAME, project=PROJECT)
subscription = self._makeOne(SUB_NAME, topic)
pulled = subscription.pull(return_immediately=False, connection=conn)
self.assertEqual(len(pulled), 0)
self.assertEqual(len(conn._requested), 1)
req = conn._requested[0]
self.assertEqual(req['method'], 'POST')
self.assertEqual(req['path'], '/%s:pull' % SUB_PATH)
self.assertEqual(req['data'],
{'returnImmediately': False, 'maxMessages': 1})

def test_acknowledge_w_implicit_connection(self):
from gcloud.pubsub._testing import _monkey_defaults
PROJECT = 'PROJECT'
Expand Down