forked from platypush/platypush
Added test for the event/condition matching and parsing logic
This commit is contained in:
parent
2a192dacc1
commit
691a9c8593
2 changed files with 32 additions and 0 deletions
|
@ -109,6 +109,7 @@ class EventAction(Request):
|
||||||
action['target'] = action['origin']
|
action['target'] = action['origin']
|
||||||
return super().build(action)
|
return super().build(action)
|
||||||
|
|
||||||
|
|
||||||
class EventHook(object):
|
class EventHook(object):
|
||||||
""" Event hook class. It consists of one conditionss and
|
""" Event hook class. It consists of one conditionss and
|
||||||
one or multiple actions to be executed """
|
one or multiple actions to be executed """
|
||||||
|
|
31
tests/test_event_parse.py
Normal file
31
tests/test_event_parse.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from platypush.event.hook import EventHook, EventCondition, EventAction
|
||||||
|
from platypush.message.event.ping import PingEvent
|
||||||
|
|
||||||
|
class TestEventParse(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.condition = EventCondition.build({
|
||||||
|
'type': 'platypush.message.event.ping.PingEvent',
|
||||||
|
'message': 'This is (the)? answer: $answer'
|
||||||
|
})
|
||||||
|
|
||||||
|
def test_event_parse(self):
|
||||||
|
message = "GARBAGE GARBAGE this is the answer: 42"
|
||||||
|
event = PingEvent(message=message)
|
||||||
|
result = event.matches_condition(self.condition)
|
||||||
|
self.assertTrue(result.is_match)
|
||||||
|
self.assertTrue('answer' in result.parsed_args)
|
||||||
|
self.assertEqual(result.parsed_args['answer'], '42')
|
||||||
|
|
||||||
|
message = "what is not the answer? 43"
|
||||||
|
event = PingEvent(message=message)
|
||||||
|
result = event.matches_condition(self.condition)
|
||||||
|
self.assertFalse(result.is_match)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue