@@ -284,10 +284,32 @@ def test_topic_publish_hit(self):
284284 msg_data = connection ._called_with ['data' ]['messages' ][0 ]['data' ]
285285 self .assertEqual (msg_data , B64_PAYLOAD )
286286
287+ def test_topic_publish_twice (self ):
288+ import base64
289+
290+ PAYLOAD = b'This is the message text'
291+ B64_PAYLOAD = base64 .b64encode (PAYLOAD ).decode ('ascii' )
292+ MESSAGE = {'data' : PAYLOAD , 'attributes' : {}}
293+ RETURNED = {'messageIds' : []}
294+ connection = _Connection (RETURNED , RETURNED )
295+ client = _Client (connection , self .PROJECT )
296+ api = self ._make_one (client )
297+
298+ api .topic_publish (self .TOPIC_PATH , [MESSAGE ])
299+ api .topic_publish (self .TOPIC_PATH , [MESSAGE ])
300+
301+ messages = connection ._called_with ['data' ]['messages' ]
302+ self .assertEqual (len (messages ), 1 )
303+ self .assertEqual (messages [0 ]['data' ], B64_PAYLOAD )
304+
287305 def test_topic_publish_miss (self ):
306+ import base64
288307 from google .cloud .exceptions import NotFound
308+
289309 PAYLOAD = b'This is the message text'
310+ B64_PAYLOAD = base64 .b64encode (PAYLOAD ).decode ('ascii' )
290311 MESSAGE = {'data' : PAYLOAD , 'attributes' : {}}
312+ B64MSG = {'data' : B64_PAYLOAD , 'attributes' : {}}
291313 connection = _Connection ()
292314 client = _Client (connection , self .PROJECT )
293315 api = self ._make_one (client )
@@ -299,7 +321,7 @@ def test_topic_publish_miss(self):
299321 path = '/%s:publish' % (self .TOPIC_PATH ,)
300322 self .assertEqual (connection ._called_with ['path' ], path )
301323 self .assertEqual (connection ._called_with ['data' ],
302- {'messages' : [MESSAGE ]})
324+ {'messages' : [B64MSG ]})
303325
304326 def test_topic_list_subscriptions_no_paging (self ):
305327 from google .cloud .pubsub .topic import Topic
0 commit comments