def test_delete_completedjob(self): request = testing.DummyRequest() job = self.fake_job() views = InCompleteJobViews(job, request) response = views.delete() exp_response = {'success': True, 'message': 'Deleted job'} self.assertDictEqual(response, exp_response) job.delete.assert_called_with() self.assertEquals(request.response.status_int, 204)
def test_delete_erroredjob(self): request = testing.DummyRequest() job = self.fake_job() # make job incomplete job.is_complete.side_effect = JobError(job) views = InCompleteJobViews(job, request) # see if cancel is called on job_factory views.job_factory = Mock(JobFactory) views.delete() job.delete.assert_called_with()
def test_set_jobstatus(self): request = testing.DummyRequest(content_type='text/plain') request.body = 'STOPPED' job = self.fake_job() job.id = 'bla' job.state = 'RUNNING' views = InCompleteJobViews(job, request) response = views.set_job_status() self.assertEqual(response, dict(status='STOPPED', jobid='bla')) self.assertEqual(job.state, 'STOPPED')
def test_jobstatus_completewitherror(self): request = testing.DummyRequest() job = self.fake_job() job.id = 'bla' job.state = 'ERROR' job.is_complete.side_effect = JobError(job) views = InCompleteJobViews(job, request) with self.assertRaises(JobError) as e: views.job_status() self.assertEquals(e.exception.job, job)
def test_stdout(self): request = testing.DummyRequest() job = self.fake_job() log = StringIO() log.write('bla') log.seek(0) job.stdout.return_value = log views = InCompleteJobViews(job, request) response = views.stdout() self.assertEqual(response.content_type, 'text/plain') self.assertMultiLineEqual(response.app_iter.read(), 'bla')
def test_error(self): request = testing.DummyRequest() job = self.fake_job() exc = JobError(job) views = InCompleteJobViews(exc, request) response = views.error() eresponse = { 'exception': exc, 'job': job, 'run': job.db.runInfo(), } self.assertEqual(response, eresponse)
def test_delete_unable2cancel(self): request = testing.DummyRequest() job = self.fake_job() # make job incomplete job.is_complete.side_effect = JobIncomplete(job) views = InCompleteJobViews(job, request) from requests.exceptions import ConnectionError exc = ConnectionError('[Errno 111] Connection refused') views.job_factory.cancel = Mock(side_effect=exc) from pyramid.httpexceptions import HTTPInternalServerError with self.assertRaises(HTTPInternalServerError) as e: views.delete() expected = '{"msg": "Failed to cancel job", "success": false}' self.assertEquals(e.exception.body, expected)
def test_jobstatusjson_completewitherror(self): request = testing.DummyRequest() job = self.fake_job() job.id = 'bla' job.state = 'ERROR' job.is_complete.side_effect = JobError(job) views = InCompleteJobViews(job, request) response = views.job_status_json() self.assertEqual(response, dict( status='ERROR', jobid='bla', is_complete=True, ))
def test_jobstatusjson_incomplete(self): request = testing.DummyRequest() job = self.fake_job() job.id = 'bla' job.state = 'STOPPED' job.is_complete.return_value = True views = InCompleteJobViews(job, request) response = views.job_status_json() self.assertEqual( response, dict( status='STOPPED', jobid='bla', is_complete=True, ))
def test_jobstatusjson_complete(self): request = testing.DummyRequest() job = self.fake_job() job.id = 'bla' job.state = 'RUNNING' job.is_complete.side_effect = JobIncomplete(job) views = InCompleteJobViews(job, request) response = views.job_status_json() self.assertEqual( response, dict( status='RUNNING', jobid='bla', is_complete=False, ))
def test_job_incomplete(self): request = testing.DummyRequest() job = self.fake_job() job.id = 'bla' job.state = 'RUNNING' job.is_complete.return_value = False exc = JobIncomplete(job) views = InCompleteJobViews(exc, request) response = views.job_incomplete() self.assertEqual( response, dict( status='RUNNING', jobid='bla', is_complete=False, ))
def test_resuls_cantrun(self, has_permission): from pyramid.security import Denied has_permission.return_value = Denied('Faked denied') request = testing.DummyRequest() job = self.fake_job() views = InCompleteJobViews(job, request) response = views.results() exp_response = dict( jobid='foo', run='bla', maxmslevel=3, canRun=False, job=job, ) self.assertDictEqual(response, exp_response) has_permission.assert_called_with('run', job, request)
def test_set_jobstatus_withjson_doneerr_exitcode(self): body = '{"state": "STOPPED", "exitCode": 1, "running": false, ' body += '"done": true, "schedulerSpecficInformation": null, ' body += '"exception": null}' request = testing.DummyRequest( content_type='application/json', charset='UTF-8', body=body, ) job = self.fake_job() job.id = 'bla' job.state = 'PENDING' views = InCompleteJobViews(job, request) response = views.set_job_status() self.assertEqual(response, dict(status='ERROR', jobid='bla')) self.assertEqual(job.state, 'ERROR')
def test_updatejson(self): request = testing.DummyRequest() request.json_body = { "id": "bar", "description": "New description", "ms_filename": "F12345.mzxml", "created_at": "1999-12-17T13:45:04", "is_public": True, } job = self.fake_job() expected_id = job.id execpted_ca = job.created_at views = InCompleteJobViews(job, request) response = views.updatejson() exp_response = {'success': True, 'message': 'Updated job'} self.assertDictEqual(response, exp_response) self.assertEqual(job.id, expected_id) self.assertEqual(job.description, 'New description') self.assertEqual(job.ms_filename, 'F12345.mzxml') self.assertEqual(job.created_at, execpted_ca) self.assertEqual(job.is_public, True)