Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the message summary a property #25

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
Release Notes
=============

master
======

API Changes
-----------

* ``fedora_messaging.message.Message.summary`` is now a property rather than
a method.


v1.0.0a1
========

Expand Down
2 changes: 1 addition & 1 deletion docs/consuming.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ called when a message arrives::
message (fedora_messaging.api.Message): The message from AMQP.
"""
if self.summary:
print(message.summary())
print(message.summary)
else:
print(message)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_summary(self):
"""Assert the summary matches the message subject."""
message = self.msg_class(body=self.full_message)

self.assertEqual('A sample email', message.summary())
self.assertEqual('A sample email', message.summary)

def test_subject(self):
"""Assert the message provides a "subject" attribute."""
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/conversion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ dumped to JSON. The schema could be written as::
'required': ['agent', 'election'],
}

Use this schema and adapt the ``__str__()`` and ``summary()`` methods.
Use this schema and adapt the ``__str__()`` method and the ``summary`` property.

Since the schema is distributed in a separate python package, it must be added
to the ``election`` app's dependencies in ``requirements.txt``.
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/schemas.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Change the ``__str__()`` method to use the expected items from the message body.
return '{owner} did something to the {package} package'.format(
owner=self._body['owner'], package=self._body['package']['name'])

Also edit the ``summary()`` method to return something relevant.
Also edit the ``summary`` property to return something relevant.


Testing it
Expand Down
23 changes: 12 additions & 11 deletions fedora_messaging/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ def _encoded_body(self):
"""The encoded body used to publish the message."""
return json.dumps(self._body).encode('utf-8')

@property
def summary(self):
"""
A short, human-readable representation of this message.

This should provide a short summary of the message, much like the subject line
of an email.

The default implementation is to simply return the message topic.
"""
return self.topic

def __str__(self):
"""
A human-readable representation of this message.
Expand Down Expand Up @@ -273,17 +285,6 @@ def __eq__(self, other):
return (isinstance(other, self.__class__) and self.topic == other.topic and
self._body == other._body and self._headers == other._headers)

def summary(self):
"""
A short, human-readable representation of this message.

This should provide a short summary of the message, much like the subject line
of an email.

The default implementation is to simply return the message topic.
"""
return self.topic

def validate(self):
"""
Validate the headers and body with the message schema, if any.
Expand Down
2 changes: 1 addition & 1 deletion fedora_messaging/tests/unit/test_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MessageTests(unittest.TestCase):
def test_summary(self):
"""Assert message summaries default to the message topic."""
msg = message.Message(topic='test.topic')
self.assertEqual(msg.topic, msg.summary())
self.assertEqual(msg.topic, msg.summary)

def test_str(self):
"""Assert calling str on a message produces a human-readable result."""
Expand Down