def test_start_task(self, start_scan): """Test start pending task.""" scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT) scan_job.save() scan_job.sources.add(self.source) # Job in created state tasks = scan_job.tasks.all() # Queue job to run scan_job.queue() self.assertEqual(scan_job.status, ScanTask.PENDING) # Queue should have created scan tasks tasks = scan_job.tasks.all() self.assertEqual(len(tasks), 1) # Start job scan_job.start()
def test_pause_restart_task(self, start_scan): """Test pause and restart task.""" scan_job = ScanJob(scan_type=ScanTask.SCAN_TYPE_CONNECT) scan_job.save() scan_job.sources.add(self.source) # Job in created state tasks = scan_job.tasks.all() # Queue job to run scan_job.queue() self.assertEqual(scan_job.status, ScanTask.PENDING) # Queue should have created scan tasks tasks = scan_job.tasks.all() self.assertEqual(len(tasks), 1) connect_task = scan_job.tasks.first() self.assertEqual(connect_task.status, ScanTask.PENDING) # Start job scan_job.start() self.assertEqual(scan_job.status, ScanTask.RUNNING) scan_job.pause() connect_task = scan_job.tasks.first() self.assertEqual(scan_job.status, ScanTask.PAUSED) self.assertEqual(connect_task.status, ScanTask.PAUSED) scan_job.restart() connect_task = scan_job.tasks.first() self.assertEqual(scan_job.status, ScanTask.RUNNING) self.assertEqual(connect_task.status, ScanTask.PENDING) scan_job.cancel() connect_task = scan_job.tasks.first() self.assertEqual(scan_job.status, ScanTask.CANCELED) self.assertEqual(connect_task.status, ScanTask.CANCELED)
def test_queue_invalid_state_changes(self): """Test create queue failed.""" scan_job = ScanJob(status=ScanTask.FAILED, scan_type=ScanTask.SCAN_TYPE_INSPECT) scan_job.save() scan_job.sources.add(self.source) # Queue job to run scan_job.queue() self.assertEqual(scan_job.status, ScanTask.FAILED) scan_job.complete() self.assertEqual(scan_job.status, ScanTask.FAILED) scan_job.pause() self.assertEqual(scan_job.status, ScanTask.FAILED) scan_job.start() self.assertEqual(scan_job.status, ScanTask.FAILED) scan_job.cancel() self.assertEqual(scan_job.status, ScanTask.FAILED) scan_job.restart() self.assertEqual(scan_job.status, ScanTask.FAILED) scan_job.fail() self.assertEqual(scan_job.status, ScanTask.FAILED) scan_job.status = ScanTask.CREATED scan_job.fail() self.assertEqual(scan_job.status, ScanTask.CREATED) scan_job.status = ScanTask.RUNNING scan_job.complete() self.assertEqual(scan_job.status, ScanTask.COMPLETED)