예제 #1
0
    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)
예제 #2
0
    def test_listen(self):
        listen_port = 8000
        test_message = pickle.dumps('test_message')
        event_manager = EventManager([], listen_port);

        # Wait for thread to be ready
        while not event_manager.is_listening():
            time.sleep(0)

        # Mock the event_received method
        m = mox.Mox()
        mock_event_received = m.CreateMockAnything()
        event_manager.event_received = new.instancemethod(mock_event_received,
                                                          event_manager)
        mock_event_received(event_manager, 'test_message')
        m.ReplayAll()

        s = socket.create_connection((socket.gethostname(), listen_port))
        s.sendall(test_message)
        s.shutdown(socket.SHUT_RDWR)
        s.close()

        event_manager.shutdown()
        
        # Make sure event_received was called on the EventManager
        m.VerifyAll()
예제 #3
0
    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)