Skip to content

Commit 9fade02

Browse files
committed
Fix regression3 failures:
- Message payload must be bytes, base64ed, but then must be serializable to JSON. - Likewise, 'attributes' values must be serializable to JSON.
1 parent 227045a commit 9fade02

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

gcloud/pubsub/test_topic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ def test_delete(self):
126126
self.assertEqual(req['method'], 'DELETE')
127127
self.assertEqual(req['path'], '/%s' % PATH)
128128

129-
def test_publish_single_wo_attrs(self):
129+
def test_publish_single_bytes_wo_attrs(self):
130130
import base64
131131
TOPIC_NAME = 'topic_name'
132132
PROJECT = 'PROJECT'
133133
PAYLOAD = b'This is the message text'
134-
B64 = base64.b64encode(PAYLOAD)
134+
B64 = base64.b64encode(PAYLOAD).decode('ascii')
135135
MSGID = 'DEADBEEF'
136136
MESSAGE = {'data': B64,
137137
'attributes': {}}
@@ -151,7 +151,7 @@ def test_publish_single_w_attrs(self):
151151
TOPIC_NAME = 'topic_name'
152152
PROJECT = 'PROJECT'
153153
PAYLOAD = b'This is the message text'
154-
B64 = base64.b64encode(PAYLOAD)
154+
B64 = base64.b64encode(PAYLOAD).decode('ascii')
155155
MSGID = 'DEADBEEF'
156156
MESSAGE = {'data': B64,
157157
'attributes': {'attr1': 'value1', 'attr2': 'value2'}}

gcloud/pubsub/topic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ def publish(self, message, **attrs):
113113
:rtype: str
114114
:returns: message ID assigned by the server to the published message
115115
"""
116-
message_data = {'data': base64.b64encode(message), 'attributes': attrs}
116+
message_b = base64.b64encode(message).decode('ascii')
117+
message_data = {'data': message_b, 'attributes': attrs}
117118
data = {'messages': [message_data]}
118119
response = self.connection.api_request(method='POST',
119120
path='%s:publish' % self.path,

regression/pubsub.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_message_pull_mode_e2e(self):
114114
self.to_delete.append(subscription)
115115

116116
MESSAGE = b'MESSAGE'
117-
EXTRA = b'EXTRA'
117+
EXTRA = 'EXTRA'
118118
topic.publish(MESSAGE, extra=EXTRA)
119119

120120
received = subscription.pull()

0 commit comments

Comments
 (0)