def test_ignore_orphan_event(self): """Check if an orphan event is ignored""" handler = StartedJobHandler(self.task_scheduler) event = JobEvent(JobEventType.STARTED, 0, 'mytask', None) handled = handler(event) self.assertEqual(handled, False)
def test_task_status(self): """Check if the handler changes the task status to running""" handler = StartedJobHandler(self.task_scheduler) task = self.registry.add('mytask', 'git', 'commit', {}) event = JobEvent(JobEventType.STARTED, 0, 'mytask', None) handled = handler(event) self.assertEqual(handled, True) self.assertEqual(task.status, TaskStatus.RUNNING)
def test_ignore_event_on_get_task_registry_error(self, mock_redis_get): """Check if an event is ignored when a TaskRegistryError is thrown""" mock_redis_get.side_effect = RedisError self.task_scheduler.registry.add('mytask', 'git', 'commit', {}) handler = StartedJobHandler(self.task_scheduler) result = JobResult(0, 1, 'mytask', 'git', 'commit') event = JobEvent(JobEventType.STARTED, 0, 'mytask', result) handled = handler(event) self.assertEqual(handled, False)
def test_initialization(self): """Check if the handler is correctly initialized""" handler = StartedJobHandler(self.task_scheduler) self.assertEqual(handler.task_scheduler, self.task_scheduler)