Esempio n. 1
0
    def test_add_event_handler_wrongly_raising_type_error(self):
        event_name = "put:test:here"
        event_version = 2
        event_handler = "A string is not a event, dude"

        with self.assertRaises(TypeError):
            EventDiscovery.add(event_name,
                               event_handler,
                               version=event_version)
Esempio n. 2
0
    def test_add_event_handler_with_wrong_name_raising_value_error(self):
        class FakeEventHandler(EventHandler):
            pass

        event_name = "wrong/mame:test:here"
        event_version = 2
        expected_event_handler = FakeEventHandler

        with self.assertRaises(ValueError):
            EventDiscovery.add(event_name,
                               expected_event_handler,
                               version=event_version)
Esempio n. 3
0
    def test_add_event_handler_getting_correct_one(self):
        class FakeEventHandler(EventHandler):
            pass

        event_name = "put:test:here"
        event_version = 2
        expected_event_handler = FakeEventHandler
        EventDiscovery.add(event_name,
                           expected_event_handler,
                           version=event_version)
        event_handler = EventDiscovery.get(event_name, event_version)
        self.assertEqual(expected_event_handler, event_handler)
Esempio n. 4
0
    def test_add_event_handler_getting_raising_event_not_found_exception(self):
        class FakeEventHandler(EventHandler):
            pass

        event_name = "put:test:here"
        event_version = 2
        wrong_event_version = 3
        expected_event_handler = FakeEventHandler
        EventDiscovery.add(event_name,
                           expected_event_handler,
                           version=event_version)
        with self.assertRaises(EventNotFoundException):
            EventDiscovery.get(event_name, wrong_event_version)
Esempio n. 5
0
    def test_event_instantiation(self):
        class EventTester(EventRegister):
            event_name = "event:top:zera"
            event_version = 1
            event_handler = _TestEventHandler

        EventTester.register_event()
        event = EventDiscovery.get(EventTester.event_name, EventTester.event_version)
        self.assertEqual(event, _TestEventHandler)
Esempio n. 6
0
 def process_event(cls, raw_event: str) -> str:
     event = None
     try:
         event: Event = cls.parse_event(raw_event)
         with EventContextHolder.with_context(event.id, event.flow_id,
                                              event.name) as _:
             event_handler: EventHandler = EventDiscovery.get(
                 event.name, event.version)
             response: ResponseEvent = event_handler.handle(event)
             return response.to_json()
     except EventException as exception:
         return EventBuilder.error_for(exception, event).to_json()