diff --git a/pubsub/google/cloud/pubsub/message.py b/pubsub/google/cloud/pubsub/message.py index 2f810baa5e2e..b20b901639be 100644 --- a/pubsub/google/cloud/pubsub/message.py +++ b/pubsub/google/cloud/pubsub/message.py @@ -89,5 +89,5 @@ def from_api_repr(cls, api_repr): instance = cls( data=data, message_id=api_repr['messageId'], attributes=api_repr.get('attributes')) - instance._service_timestamp = api_repr.get('publishTimestamp') + instance._service_timestamp = api_repr.get('publishTime') return instance diff --git a/pubsub/unit_tests/test_message.py b/pubsub/unit_tests/test_message.py index 5d08972e5430..8187eea3cf06 100644 --- a/pubsub/unit_tests/test_message.py +++ b/pubsub/unit_tests/test_message.py @@ -98,7 +98,7 @@ def test_from_api_repr_no_attributes(self): api_repr = { 'data': B64_DATA, 'messageId': MESSAGE_ID, - 'publishTimestamp': TIMESTAMP, + 'publishTime': TIMESTAMP, } message = self._getTargetClass().from_api_repr(api_repr) self.assertEqual(message.data, DATA) @@ -116,7 +116,7 @@ def test_from_api_repr_w_attributes(self): api_repr = { 'data': B64_DATA, 'messageId': MESSAGE_ID, - 'publishTimestamp': TIMESTAMP, + 'publishTime': TIMESTAMP, 'attributes': ATTRS, } message = self._getTargetClass().from_api_repr(api_repr) diff --git a/system_tests/pubsub.py b/system_tests/pubsub.py index 5e4343066de0..25f24427d0f7 100644 --- a/system_tests/pubsub.py +++ b/system_tests/pubsub.py @@ -198,10 +198,14 @@ def suction(self): message1, message2 = sorted(hoover.received, key=operator.attrgetter('timestamp')) + self.assertEqual(message1.data, MESSAGE_1) self.assertEqual(message1.attributes['extra'], EXTRA_1) + self.assertIsNotNone(message1.service_timestamp) + self.assertEqual(message2.data, MESSAGE_2) self.assertEqual(message2.attributes['extra'], EXTRA_2) + self.assertIsNotNone(message2.service_timestamp) def _maybe_emulator_skip(self): # NOTE: This method is necessary because ``Config.IN_EMULATOR``