def test_subscribe_same(self): event_type = 'test_event_type' controller = 'dummy_controller' event_manager = EventManager([]); event_manager.subscribe(event_type, controller) event_manager.subscribe(event_type, controller) self.assertEqual(len(event_manager.subscriptions[event_type]), 1)
def test_event_received(self): event_type = EventType.DOOR_SENSOR_EVENT event = Event(event_type) # Set up controller mock controller = mox.MockObject(Controller) controller.handle_event(event) mox.Replay(controller) event_manager = EventManager([]); event_manager.subscribe(event_type, controller) event_manager.event_received(event) event_manager.process_events() mox.Verify(controller)
def test_event_received_multiple_events(self): door_event = Event(EventType.DOOR_SENSOR_EVENT) window_event = Event(EventType.WINDOW_SENSOR_EVENT) # Set up controller mocks door_controller = mox.MockObject(Controller) door_controller.handle_event(door_event) mox.Replay(door_controller) window_controller = mox.MockObject(Controller) mox.Replay(window_controller) event_manager = EventManager([]); event_manager.subscribe(EventType.DOOR_SENSOR_EVENT, door_controller) event_manager.subscribe(EventType.WINDOW_SENSOR_EVENT, window_controller) # Send event event_manager.event_received(door_event) event_manager.process_events() mox.Verify(door_controller) mox.Verify(window_controller)