예제 #1
0
    def test_send_event(self, mock_open, mock_dump, mock_load, mock_thread):
        """
            Test save functionality.
        """
        mock_load.return_value = ''
        mock_open.return_value = MagicMock()
        emitter = MagicMock()
        es = EventScheduler(emitter)

        # 0 should be in the future for a long time
        es.schedule_event('test', time.time(), None)

        es.check_state()
        self.assertEqual(emitter.emit.call_args[0][0].msg_type, 'test')
        self.assertEqual(emitter.emit.call_args[0][0].data, {})
        es.shutdown()
예제 #2
0
    def test_send_event(self, mock_open, mock_dump, mock_load, mock_thread):
        """
            Test save functionality.
        """
        mock_load.return_value = ''
        mock_open.return_value = mock.MagicMock()
        emitter = mock.MagicMock()
        es = EventScheduler(emitter)

        # 0 should be in the future for a long time
        es.schedule_event('test', time.time(), None)

        es.check_state()
        self.assertEquals(emitter.emit.call_args[0][0].type, 'test')
        self.assertEquals(emitter.emit.call_args[0][0].data, {})
        es.shutdown()
예제 #3
0
    def test_save(self, mock_open, mock_dump, mock_load, mock_thread):
        """
            Test save functionality.
        """
        mock_load.return_value = ''
        mock_open.return_value = MagicMock()
        emitter = MagicMock()
        es = EventScheduler(emitter)

        # 900000000000 should be in the future for a long time
        es.schedule_event('test', 900000000000, None)
        es.schedule_event('test-repeat', 910000000000, 60)
        es.check_state()

        es.shutdown()

        # Make sure the dump method wasn't called with test-repeat
        self.assertEqual(mock_dump.call_args[0][0],
                         {'test': [(900000000000, None, {}, None)]})
예제 #4
0
    def test_save(self, mock_open, mock_dump, mock_load, mock_thread):
        """
            Test save functionality.
        """
        mock_load.return_value = ''
        mock_open.return_value = mock.MagicMock()
        emitter = mock.MagicMock()
        es = EventScheduler(emitter)

        # 900000000000 should be in the future for a long time
        es.schedule_event('test', 900000000000, None)
        es.schedule_event('test-repeat', 910000000000, 60)
        es.check_state()

        es.shutdown()

        # Make sure the dump method wasn't called with test-repeat
        self.assertEquals(mock_dump.call_args[0][0],
                          {'test': [(900000000000, None, {})]})
예제 #5
0
    def test_add_remove(self, mock_open, mock_json_dump, mock_load,
                        mock_thread):
        """
            Test add an event and then remove it.
        """
        # Thread start is mocked so will not actually run the thread loop
        mock_load.return_value = ''
        mock_open.return_value = MagicMock()
        emitter = MagicMock()
        es = EventScheduler(emitter)

        # 900000000000 should be in the future for a long time
        es.schedule_event('test', 90000000000, None)
        es.schedule_event('test-2', 90000000000, None)

        es.check_state()  # run one cycle
        self.assertTrue('test' in es.events)
        self.assertTrue('test-2' in es.events)

        es.remove_event('test')
        es.check_state()  # run one cycle
        self.assertTrue('test' not in es.events)
        self.assertTrue('test-2' in es.events)
        es.shutdown()
예제 #6
0
    def test_add_remove(self, mock_open, mock_json_dump,
                        mock_load, mock_thread):
        """
            Test add an event and then remove it.
        """
        # Thread start is mocked so will not actually run the thread loop
        mock_load.return_value = ''
        mock_open.return_value = mock.MagicMock()
        emitter = mock.MagicMock()
        es = EventScheduler(emitter)

        # 900000000000 should be in the future for a long time
        es.schedule_event('test', 90000000000, None)
        es.schedule_event('test-2', 90000000000, None)

        es.check_state()  # run one cycle
        self.assertTrue('test' in es.events)
        self.assertTrue('test-2' in es.events)

        es.remove_event('test')
        es.check_state()  # run one cycle
        self.assertTrue('test' not in es.events)
        self.assertTrue('test-2' in es.events)
        es.shutdown()