def test_start_job_new_state(self, mock_give_download_permissions, mock_make_client): job = LandoJob(self.job.id, self.user) with self.assertRaises(ValidationError) as raised_exception: job.start() self.assertEqual(raised_exception.exception.detail[0], 'Job needs authorization token before it can start.')
def test_restart_job_in_record_output_step(self): self.job.state = Job.JOB_STATE_ERROR self.job.step = Job.JOB_STEP_RECORD_OUTPUT_PROJECT self.job.save() job = LandoJob(self.job.id, self.user) with self.assertRaises(ValidationError) as raised_error: job.restart()
def test_start_job_already_has_perms(self, mock_give_download_permissions, mock_has_download_permissions, mock_make_client): self.job.state = Job.JOB_STATE_AUTHORIZED self.job.save() mock_has_download_permissions.return_value = True job = LandoJob(self.job.id, self.user) job.start() mock_make_client().start_job.assert_called() self.assertFalse(mock_give_download_permissions.called)
def test_start_job(self, mock_give_download_permissions, mock_has_download_permissions, mock_make_client): self.job.state = Job.JOB_STATE_AUTHORIZED self.job.save() mock_has_download_permissions.return_value = False job = LandoJob(self.job.id, self.user) job.start() mock_make_client().start_job.assert_called() mock_give_download_permissions.assert_has_calls( [call(self.user, '1234', '5432'), call(self.user, '1235', '5432')], any_order=True)
def restart(self, request, pk=None): try: LandoJob(pk, request.user).restart() return self._serialize_job_response(pk) except Job.DoesNotExist: raise NotFound("Job {} not found.".format(pk))