def test_manual_execute(self): waiter = Event() # noinspection PyUnusedLocal def execute(*args, **kwargs): waiter.set() execute_mock = Mock(side_effect=execute) mock_tracker = Mock() mock_tracker.get_topics = Mock(return_value=[Topic()]) mock_tracker.execute = execute_mock self.trackers_manager.trackers = {'mock.tracker': mock_tracker} self.create_runner(interval=1) self.engine_runner.execute(None) waiter.wait(0.3) self.assertTrue(waiter.is_set) self.stop_runner() self.assertEqual(1, execute_mock.call_count)
def test_manual_execute_with_ids(self): waiter = Event() # noinspection PyUnusedLocal def execute(*args, **kwargs): waiter.set() execute_mock = Mock(side_effect=execute) topics = [Topic()] mock_tracker = Mock() mock_tracker.get_topics = Mock(return_value=topics) mock_tracker.execute = execute_mock self.trackers_manager.trackers = {'mock.tracker': mock_tracker} self.create_runner(interval=10) ids = [1, 2, 3] self.engine_runner.execute(ids) self.assertTrue(waiter.wait(0.3)) self.stop_runner() execute_mock.assert_called_once_with(topics, ANY)
def test_exeption_in_finally_execute(self): waiter = Event() # noinspection PyUnusedLocal def execute(*args, **kwargs): waiter.set() execute_mock = Mock(side_effect=execute) mock_tracker = Mock() mock_tracker.get_topics = Mock(return_value=[Topic()]) mock_tracker.execute = execute_mock self.trackers_manager.trackers = {'mock.tracker': mock_tracker} logger = Logger() logger.finished = Mock(side_effect=Exception("Failed to save")) self.create_runner(logger=logger) self.assertTrue(waiter.wait(1)) self.assertTrue(self.engine_runner.is_alive()) self.stop_runner() self.assertEqual(1, execute_mock.call_count)