Skip to content

Commit

Permalink
Shorten attribute name.
Browse files Browse the repository at this point in the history
Addresses:
#809 (comment).
  • Loading branch information
tseaver committed Apr 10, 2015
1 parent 80503a8 commit 9264828
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions gcloud/pubsub/test_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_ctor_wo_inferred_project_or_connection(self):
self.assertEqual(topic.full_name,
'projects/%s/topics/%s' % (PROJECT, TOPIC_NAME))
self.assertTrue(topic.connection is conn)
self.assertFalse(topic.add_timestamp_to_messages)
self.assertFalse(topic.timestamp_messages)

def test_ctor_w_explicit_project_connection_and_timestamp(self):
TOPIC_NAME = 'topic_name'
Expand All @@ -47,13 +47,13 @@ def test_ctor_w_explicit_project_connection_and_timestamp(self):
topic = self._makeOne(TOPIC_NAME,
project=PROJECT,
connection=conn,
add_timestamp_to_messages=True)
timestamp_messages=True)
self.assertEqual(topic.name, TOPIC_NAME)
self.assertEqual(topic.project, PROJECT)
self.assertEqual(topic.full_name,
'projects/%s/topics/%s' % (PROJECT, TOPIC_NAME))
self.assertTrue(topic.connection is conn)
self.assertTrue(topic.add_timestamp_to_messages)
self.assertTrue(topic.timestamp_messages)

def test_from_api_repr_wo_connection(self):
from gcloud.pubsub._testing import _monkey_defaults
Expand Down Expand Up @@ -171,7 +171,7 @@ def _utcnow():
PATH = 'projects/%s/topics/%s' % (PROJECT, TOPIC_NAME)
conn = _Connection({'messageIds': [MSGID]})
topic = self._makeOne(TOPIC_NAME, project=PROJECT, connection=conn,
add_timestamp_to_messages=True)
timestamp_messages=True)
with _Monkey(MUT, _NOW=_utcnow):
msgid = topic.publish(PAYLOAD)
self.assertEqual(msgid, MSGID)
Expand Down
14 changes: 7 additions & 7 deletions gcloud/pubsub/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ class Topic(object):
:param connection: the connection to use. If not passed,
falls back to the default inferred from the
:type add_timestamp_to_messages: boolean
:param add_timestamp_to_messages: If true, the topic will add a key,
``timestamp``, to the attributes of each published
method: the value will be an RFC 3339 timestamp.
:type timestamp_messages: boolean
:param timestamp_messages: If true, the topic will add a ``timestamp`` key
to the attributes of each published message:
the value will be an RFC 3339 timestamp.
"""
def __init__(self, name, project=None, connection=None,
add_timestamp_to_messages=False):
timestamp_messages=False):
if project is None:
project = get_default_project()
if connection is None:
connection = get_default_connection()
self.name = name
self.project = project
self.connection = connection
self.add_timestamp_to_messages = add_timestamp_to_messages
self.timestamp_messages = timestamp_messages

@classmethod
def from_api_repr(cls, resource, connection=None):
Expand Down Expand Up @@ -122,7 +122,7 @@ def publish(self, message, **attrs):
:rtype: str
:returns: message ID assigned by the server to the published message
"""
if self.add_timestamp_to_messages:
if self.timestamp_messages:
attrs['timestamp'] = '%sZ' % _NOW().isoformat()
message_b = base64.b64encode(message).decode('ascii')
message_data = {'data': message_b, 'attributes': attrs}
Expand Down

0 comments on commit 9264828

Please sign in to comment.