Esempio n. 1
0
 def test_prepare_job_result_with_failed(self):
     """
     The result dictionary for failed OpenQuake jobs is prepared correctly.
     """
     post_params = get_post_params()
     job = prepare_job(post_params)
     self.upload = job.oq_params.upload
     job.status = "failed"
     self.assertEqual(
         {"msg": "Calculation failed", "status": "failure",
          "id": job.id},
         prepare_job_result(job))
Esempio n. 2
0
 def test_prepare_job_result_with_succeeded_no_maps(self):
     """
     The result dictionary for succeeded OpenQuake jobs (w/o hazard/loss
     maps) is prepared correctly.
     """
     post_params = get_post_params()
     job = prepare_job(post_params)
     self.upload = job.oq_params.upload
     job.status = "succeeded"
     self.assertEqual(
         {"msg": "Calculation succeeded", "status": "success",
         "id": job.id, "files": []},
         prepare_job_result(job))
Esempio n. 3
0
    def test_prepare_job_result_with_succeeded_and_maps(self):
        """
        The result dictionary for succeeded OpenQuake jobs (w/o hazard/loss
        maps) is prepared correctly.
        """
        hazard_map = self.setup_output()
        self.job_to_teardown = job = hazard_map.oq_job
        self.add_shapefile_data(hazard_map)
        hazard_layer, _ = os.path.splitext(
            os.path.basename(hazard_map.shapefile_path))
        hazard_file = os.path.basename(hazard_map.path)

        loss_map = self.setup_output(job_to_use=job, output_type="loss_map")
        self.add_shapefile_data(loss_map)
        loss_layer, _ = os.path.splitext(
            os.path.basename(loss_map.shapefile_path))
        loss_file = os.path.basename(loss_map.path)
        job.status = "succeeded"
        expected = {
            "id": job.id,
            "msg": "Calculation succeeded",
            "status": "success",
            "files": [
                {"id": hazard_map.id,
                 "layer": {
                    "layer": "geonode:hazard_map_data",
                    "filter": "output_id=%s" % hazard_map.id,
                    "ows": "http://gemsun02.ethz.ch/geoserver-geonode-dev/ows"},
                "min": view_utils.round_float(hazard_map.min_value),
                "max": view_utils.round_float(hazard_map.max_value),
                "name": "%s-%s" % (job.id, hazard_file),
                "type": "hazard map"},
                {"id": loss_map.id,
                 "layer": {
                    "layer": "geonode:loss_map_data",
                    "filter": "output_id=%s" % loss_map.id,
                    "ows": "http://gemsun02.ethz.ch/geoserver-geonode-dev/ows"},
                "min": view_utils.round_float(loss_map.min_value),
                "max": view_utils.round_float(loss_map.max_value),
                "name": "%s-%s" % (job.id, loss_file),
                "type": "loss map"}]}

        actual = prepare_job_result(job)
        self.assertEqual(expected, actual)