From 691a9c8593174c1aae7ff2f7af5c8c0f7f007e51 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 3 Jan 2018 00:16:01 +0100 Subject: [PATCH] Added test for the event/condition matching and parsing logic --- platypush/event/hook.py | 1 + tests/test_event_parse.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/test_event_parse.py diff --git a/platypush/event/hook.py b/platypush/event/hook.py index 82d252ee93..fb81e785ee 100644 --- a/platypush/event/hook.py +++ b/platypush/event/hook.py @@ -109,6 +109,7 @@ class EventAction(Request): action['target'] = action['origin'] return super().build(action) + class EventHook(object): """ Event hook class. It consists of one conditionss and one or multiple actions to be executed """ diff --git a/tests/test_event_parse.py b/tests/test_event_parse.py new file mode 100644 index 0000000000..7098352ecb --- /dev/null +++ b/tests/test_event_parse.py @@ -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: +