def test_get_jobs_info_by_type(self): foo = FooJob() jobs.add(foo) bar = BarJob() jobs.add(bar) self.assertEqual({bar.id: bar.info()}, jobs.info(job_type=bar.job_type))
def test_get_jobs_info_by_uuid_multi(self): foo = FooJob() jobs.add(foo) bar = BarJob() jobs.add(bar) self.assertEqual({foo.id: foo.info(), bar.id: bar.info()}, jobs.info(job_ids=[foo.id, bar.id]))
def test_get_jobs_info_by_type_and_uuid(self): foo = FooJob() jobs.add(foo) bar = BarJob() jobs.add(bar) self.assertEqual({}, jobs.info(job_type=bar.job_type, job_ids=[foo.id]))
def test_autodelete_when_aborted(self): cfg = make_config([('jobs', 'autodelete_delay', '10')]) job = AutodeleteJob() jobs.add(job) with MonkeyPatchScope([(jobs, 'config', cfg)]): job.abort() self._verify_autodelete(job, 10)
def test_autodelete_disabled(self): cfg = make_config([('jobs', 'autodelete_delay', '-1')]) job = AutodeleteJob() jobs.add(job) with MonkeyPatchScope([(jobs, 'config', cfg)]): self.run_job(job) self.assertEqual(0, len(self.scheduler.calls))
def test_autodelete_when_finished(self, error): cfg = make_config([('jobs', 'autodelete_delay', '10')]) job = AutodeleteJob(exception=error) jobs.add(job) with MonkeyPatchScope([(jobs, 'config', cfg)]): self.run_job(job) self._verify_autodelete(job, 10)
def test_get_jobs_info_any(self): foo = FooJob() jobs.add(foo) bar = BarJob() jobs.add(bar) self.assertEqual({foo.id: foo.info(), bar.id: bar.info()}, jobs.info())
def test_abort_running_job(self): job = StuckJob() jobs.add(job) t = start_thread(job.run) job.event_running.wait(1) self.assertEqual(jobs.STATUS.RUNNING, job.status) jobs.abort(job.id) t.join() self.assertEqual(jobs.STATUS.ABORTED, job.status)
def test_delete_inactive_job(self, status): job = TestingJob(status) jobs.add(job) self.assertEqual(response.success(), jobs.delete(job.id))
def test_abort_not_supported(self): job = jobs.Job(str(uuid.uuid4())) job._status = jobs.STATUS.RUNNING jobs.add(job) self.assertEqual(response.error(jobs.AbortNotSupported.name), jobs.abort(job.id))
def test_abort_from_invalid_state(self, status, err): job = TestingJob(status) jobs.add(job) res = jobs.abort(job.id) self.assertEqual(response.error(err), res)
def test_abort_job(self, status, aborted_status, did_abort): job = TestingJob(status) jobs.add(job) jobs.abort(job.id) self.assertEqual(aborted_status, job.status) self.assertEqual(did_abort, job._aborted)
def test_delete_active_job(self, status): job = TestingJob() job._status = status jobs.add(job) self.assertEqual(response.error(jobs.JobNotDone.name), jobs.delete(job.id))
def test_add_existing_job(self): job = TestingJob() jobs.add(job) self.assertRaises(jobs.JobExistsError, jobs.add, job)
def test_get_job(self): job = TestingJob() jobs.add(job) self.assertEqual(job.id, jobs.get(job.id).id)
def test_abort_not_supported(self): job = jobs.Job(str(uuid.uuid4())) jobs.add(job) self.assertEqual(response.error(jobs.AbortNotSupported.name), jobs.abort(job.id))
def test_add_job(self): job = TestingJob() jobs.add(job) self.assertEqual(1, len(jobs._jobs))
def test_delete_running_job(self): job = TestingJob() jobs.add(job) self.assertEqual(response.error(jobs.JobNotDone.name), jobs.delete(job.id))
def test_delete_active_job(self, status): job = TestingJob(status) jobs.add(job) self.assertEqual(response.error(jobs.JobNotDone.name), jobs.delete(job.id))
def test_abort_job(self): job = TestingJob() jobs.add(job) jobs.abort(job.id) self.assertEqual(jobs.STATUS.ABORTED, job.status) self.assertTrue(job._aborted)
def test_delete_inactive_job(self, status): job = TestingJob() job._status = status jobs.add(job) self.assertEqual(response.success(), jobs.delete(job.id))