2018-01-03 00:16:01 +01:00
|
|
|
import unittest
|
|
|
|
|
2018-09-27 01:52:35 +02:00
|
|
|
from platypush.event.hook import EventCondition
|
2018-01-03 00:16:01 +01:00
|
|
|
from platypush.message.event.ping import PingEvent
|
|
|
|
|
2021-02-24 00:23:32 +01:00
|
|
|
|
2018-01-03 00:16:01 +01:00
|
|
|
class TestEventParse(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.condition = EventCondition.build({
|
|
|
|
'type': 'platypush.message.event.ping.PingEvent',
|
2018-01-07 23:31:19 +01:00
|
|
|
'message': 'This is (the)? answer: ${answer}'
|
2018-01-03 00:16:01 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
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:
|