Skip to content

Commit

Permalink
Merge pull request #804 from tseaver/pubsub-fix_regression-py3k_bytes…
Browse files Browse the repository at this point in the history
…_attr

Fix regression3 failures in pubsub
  • Loading branch information
tseaver committed Apr 7, 2015
2 parents 227045a + 9fade02 commit 96ee9d3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions gcloud/pubsub/test_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ def test_delete(self):
self.assertEqual(req['method'], 'DELETE')
self.assertEqual(req['path'], '/%s' % PATH)

def test_publish_single_wo_attrs(self):
def test_publish_single_bytes_wo_attrs(self):
import base64
TOPIC_NAME = 'topic_name'
PROJECT = 'PROJECT'
PAYLOAD = b'This is the message text'
B64 = base64.b64encode(PAYLOAD)
B64 = base64.b64encode(PAYLOAD).decode('ascii')
MSGID = 'DEADBEEF'
MESSAGE = {'data': B64,
'attributes': {}}
Expand All @@ -151,7 +151,7 @@ def test_publish_single_w_attrs(self):
TOPIC_NAME = 'topic_name'
PROJECT = 'PROJECT'
PAYLOAD = b'This is the message text'
B64 = base64.b64encode(PAYLOAD)
B64 = base64.b64encode(PAYLOAD).decode('ascii')
MSGID = 'DEADBEEF'
MESSAGE = {'data': B64,
'attributes': {'attr1': 'value1', 'attr2': 'value2'}}
Expand Down
3 changes: 2 additions & 1 deletion gcloud/pubsub/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ def publish(self, message, **attrs):
:rtype: str
:returns: message ID assigned by the server to the published message
"""
message_data = {'data': base64.b64encode(message), 'attributes': attrs}
message_b = base64.b64encode(message).decode('ascii')
message_data = {'data': message_b, 'attributes': attrs}
data = {'messages': [message_data]}
response = self.connection.api_request(method='POST',
path='%s:publish' % self.path,
Expand Down
2 changes: 1 addition & 1 deletion regression/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_message_pull_mode_e2e(self):
self.to_delete.append(subscription)

MESSAGE = b'MESSAGE'
EXTRA = b'EXTRA'
EXTRA = 'EXTRA'
topic.publish(MESSAGE, extra=EXTRA)

received = subscription.pull()
Expand Down

0 comments on commit 96ee9d3

Please sign in to comment.