def test_register_all(self): event_map = { "task:start": self, "task:new": self } events.register_all(event_map) events.emit("task:start") self.assertEqual(self.counter, 2) events.emit("task:stop") self.assertEqual(self.counter, 2) events.emit("task:start") self.assertEqual(self.counter, 3) events.emit("task:new") self.assertEqual(self.counter, 4)
def register_event_handlers(app): """ Load code from event handlers folder. Then it registers in the event manager each event handler listed in the __init_.py. """ sys.path.insert(0, app.config["EVENT_HANDLERS_FOLDER"]) try: import event_handlers events.register_all(event_handlers.event_map) except ImportError: # Event handlers folder is not properly configured. # Handlers are optional, that's why this error is ignored. pass return app
def test_register_all(self): event_map = {"task:start": self, "task:new": self} events.register_all(event_map) events.emit("task:start") self.assertEqual(self.counter, 2) events.emit("task:stop") self.assertEqual(self.counter, 2) events.emit("task:start") self.assertEqual(self.counter, 3) events.emit("task:new") self.assertEqual(self.counter, 4) event_models = events_service.get_last_events() self.assertEqual(len(event_models), 4) self.assertEqual(event_models[0]["name"], "task:new")
def register_event_handlers(app): sys.path.append(app.config["EVENT_HANDLERS_FOLDER"]) import event_handlers events.register_all(event_handlers.event_map)