def test_404_calc_not_complete(self): with mock.patch('openquake.engine.db.models' '.RiskCalculation.objects.get') as hc_get: hc_get.return_value.oqjob.status = 'pre_executing' response = views.calc_results(self.request, 'risk', 1) self.assertEqual(404, response.status_code)
def test(self): expected_content = [ {'id': 1, 'name': 'output1', 'type': 'hazard_curve', 'url': 'http://www.openquake.org/v1/calc/hazard/result/1'}, {'id': 2, 'name': 'output2', 'type': 'hazard_curve', 'url': 'http://www.openquake.org/v1/calc/hazard/result/2'}, {'id': 3, 'name': 'output3', 'type': 'hazard_map', 'url': 'http://www.openquake.org/v1/calc/hazard/result/3'}, ] with mock.patch('openquake.engine.engine.get_outputs') as gho: with mock.patch('openquake.engine.db.models' '.HazardCalculation.objects.get') as hc_get: hc_get.return_value.oqjob.status = 'complete' gho.return_value = [ FakeOutput(1, 'output1', 'hazard_curve'), FakeOutput(2, 'output2', 'hazard_curve'), FakeOutput(3, 'output3', 'hazard_map'), ] self.request = self.factory.get('/v1/calc/hazard/1/results') self.request.META['HTTP_HOST'] = 'www.openquake.org' response = views.calc_results(self.request, 'hazard', 7) self.assertEqual(1, gho.call_count) self.assertEqual((('hazard', 7), {}), gho.call_args) self.assertEqual(200, response.status_code) self.assertEqual(expected_content, json.loads(response.content))
def test_404_calc_not_exists(self): with mock.patch('openquake.engine.db.models' '.RiskCalculation.objects.get') as hc_get: hc_get.side_effect = ObjectDoesNotExist response = views.calc_results(self.request, 'risk', 1) self.assertEqual(404, response.status_code)
def test_404_no_outputs(self): with mock.patch('openquake.engine.engine.get_outputs') as gro: with mock.patch('openquake.engine.db.models' '.RiskCalculation.objects.get') as rc_get: rc_get.return_value.oqjob.status = 'complete' gro.return_value = [] response = views.calc_results(self.request, 'risk', 1) self.assertEqual(404, response.status_code)
def test_404_no_outputs(self): with mock.patch('openquake.engine.engine.get_outputs') as gho: with mock.patch('openquake.engine.db.models.OqJob.objects.get' ) as oqjob: oqjob.return_value.status = 'complete' gho.return_value = [] response = views.calc_results(self.request, 7) self.assertEqual(404, response.status_code)
def test(self): expected_content = [ {'id': 1, 'name': 'output1', 'type': 'loss_curve', 'url': 'http://www.openquake.org/v1/calc/risk/result/1'}, {'id': 2, 'name': 'output2', 'type': 'loss_curve', 'url': 'http://www.openquake.org/v1/calc/risk/result/2'}, {'id': 3, 'name': 'output3', 'type': 'loss_map', 'url': 'http://www.openquake.org/v1/calc/risk/result/3'}, ] with mock.patch('openquake.engine.engine.get_outputs') as gro: with mock.patch('openquake.engine.db.models' '.RiskCalculation.objects.get') as rc_get: rc_get.return_value.oqjob.status = 'complete' gro.return_value = [ FakeOutput(1, 'output1', 'loss_curve'), FakeOutput(2, 'output2', 'loss_curve'), FakeOutput(3, 'output3', 'loss_map'), ] response = views.calc_results(self.request, 'risk', 1) self.assertEqual(200, response.status_code) self.assertEqual(expected_content, json.loads(response.content))
def test_404_calc_not_complete(self): with mock.patch('openquake.engine.db.models.OqJob') as oqjob: oqjob.return_value.oqjob.status = 'pre_executing' response = views.calc_results(self.request, 7) self.assertEqual(404, response.status_code)
def test_404_calc_not_exists(self): with mock.patch('openquake.engine.db.models.OqJob') as oqjob: oqjob.side_effect = ObjectDoesNotExist response = views.calc_results(self.request, 7) self.assertEqual(404, response.status_code)