Permalink
Browse files

adding string representation of heartbeats

  • Loading branch information...
mriehl committed Mar 19, 2013
1 parent 024a410 commit 46f5c34d4c4207bf1292de12fb2dd1770fb51aea
Showing with 16 additions and 0 deletions.
  1. +7 −0 src/main/python/yadtreceiver/events.py
  2. +9 −0 src/unittest/python/event_tests.py
@@ -153,6 +153,10 @@ def is_a_service_change(self):
def is_a_command(self):
return self.event_type == TYPE_COMMAND
+ @property
+ def is_a_heartbeat(self):
+ return self.event_type == TYPE_HEARTBEAT
+
def __str__(self):
if self.is_a_request:
return 'target[{0}] requested command "{1}" using arguments "{2}"'.format(self.target, self.command, self.arguments)
@@ -170,6 +174,9 @@ def __str__(self):
else:
return '(broadcaster) target[{0}] command "{1}" {2}.'.format(self.target, self.command, self.state)
+ if self.is_a_heartbeat:
+ return 'heartbeat'
+
raise NotImplementedError('Unknown event type {0}'.format(self.event_type))
class ServiceState (object):
@@ -79,6 +79,15 @@ def test_should_return_description_of_request(self):
self.assertEqual('target[target-name] requested command "command" using arguments "arg1 arg2 arg3"', str(event))
+ def test_should_return_description_of_heartbeat(self):
+ event = Event('target-name', {'id': 'heartbeat',
+ 'type': 'event',
+ 'target': 'dev12',
+ 'tracking_id': None,
+ 'payload': None})
+
+ self.assertEqual('heartbeat', str(event))
+
def test_should_return_description_of_full_update(self):
event = Event('target-name', {'id': 'full-update'})

0 comments on commit 46f5c34

Please sign in to comment.