Skip to content

Commit

Permalink
Add test for Message.asdict
Browse files Browse the repository at this point in the history
  • Loading branch information
erik committed Jan 11, 2019
1 parent 3d4224d commit 0340e47
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions squabble/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ def explain(cls):
return inspect.cleandoc(cls.__doc__)

def asdict(self):
"""
Return dictionary representation of message, for formatting.
>>> class SummaryMessage(Message):
... '''A useful message.'''
... CODE = 90291
... TEMPLATE = 'everything is {status}'
>>> msg = SummaryMessage(status='wrong')
>>> msg.asdict() == {
... 'message_id': 'SummaryMessage',
... 'message_text': 'everything is wrong',
... 'message_template': SummaryMessage.TEMPLATE,
... 'message_params': {'status': 'wrong'},
... 'message_code': 90291
... }
True
"""
return {
'message_id': self.__class__.__name__,
'message_text': self.format(),
Expand Down

0 comments on commit 0340e47

Please sign in to comment.