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_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_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)