Esempio n. 1
0
    def test_risk_default_export_type(self):
        with mock.patch('openquake.engine.export.core.export') as export:
            with mock.patch('openquake.engine.db.models'
                            '.Output.objects.get') as output_get:
                output_get.return_value.output_type = 'test_output'
                output_get.return_value.oq_job.status = 'complete'
                export.return_value = writetmp('Fake result file content')

                request = self.factory.get('/v1/calc/result/37')
                response = views.get_result(request, 37)

                self.assertEqual(200, response.status_code)
                self.assertEqual('Fake result file content', response.content)

                self.assertEqual(1, export.call_count)
                self.assertEqual(37, export.call_args[0][0])
                self.assertEqual('xml', export.call_args[1]['export_type'])
Esempio n. 2
0
    def test_hazard_default_export_type(self):
        with mock.patch('openquake.engine.export.hazard.export') as export:
            with mock.patch('openquake.engine.db.models'
                            '.Output.objects.get') as output_get:
                output_get.return_value.oq_job.status = 'complete'
                ret_val = StringIO.StringIO()
                ret_val.write('Fake result file content')
                ret_val.close()
                export.return_value = ret_val

                request = self.factory.get('/v1/calc/hazard/result/37')
                response = views.get_result(request, 'hazard', 37)

                self.assertEqual(200, response.status_code)
                self.assertEqual('Fake result file content', response.content)

                # Test the call to the export function, including the handling
                # for the default export type:
                self.assertEqual(1, export.call_count)
                self.assertEqual(37, export.call_args[0][0])
                self.assertEqual('xml', export.call_args[1]['export_type'])
Esempio n. 3
0
    def test_risk(self):
        with mock.patch('openquake.engine.export.risk.export') as export:
            with mock.patch('openquake.engine.db.models'
                            '.Output.objects.get') as output_get:
                output_get.return_value.oq_job.status = 'complete'

                ret_val = StringIO.StringIO()
                ret_val.write('Fake result file content')
                ret_val.close()
                export.return_value = ret_val

                request = self.factory.get(
                    '/v1/calc/risk/result/37?export_type=csv'
                )
                response = views.get_result(request, 'risk', 37)

                self.assertEqual(200, response.status_code)
                self.assertEqual('Fake result file content', response.content)

                self.assertEqual(1, export.call_count)
                self.assertEqual(37, export.call_args[0][0])
                self.assertEqual('csv', export.call_args[1]['export_type'])