예제 #1
0
 def test_process_map_calls_map_transformer_correctly_with_loss_to_db(self):
     """
     The map transformer is invoked correctly for a loss map that is to be
     written to the database.
     Specifically: the '--shapefile' command line argument is not supplied.
     """
     config = {'jobid': self.job.id}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [_, loss_map] = maps
     basename = os.path.basename(loss_map.path)
     self.assertEqual("loss_map", loss_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (0, "RESULT: (%s, 19.19, 21.21)" %
                                   loss_map.id, "")
         process_map(loss_map, config)
         args, kwargs = mock_func.call_args
         expected = ([
             '%s/bin/map_transformer.py' % settings.OQ_APIAPP_DIR, '-k',
             str(loss_map.id), '-p',
             '%s/computed_output/%s' % (self.job.path, basename), '-t',
             'loss'
         ], )
         self.assertEqual(expected, args)
         self.assertEqual({'ignore_exit_code': True}, kwargs)
예제 #2
0
 def test_process_map_with_shapefile_and_loss_to_db(self):
     """The db record for the loss map is updated."""
     config = {'jobid': self.job.id}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [_, loss_map] = maps
     self.assertEqual("loss_map", loss_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (0, "RESULT: (%s, 19.19, 21.21)" %
                                   loss_map.id, "")
         process_map(loss_map, config)
         self.assertTrue(loss_map.shapefile_path is None)
         self.assertEqual(19.19, loss_map.min_value)
         self.assertEqual(21.21, loss_map.max_value)
예제 #3
0
 def test_process_map_with_shapefile_and_loss_to_db(self):
     """The db record for the loss map is updated."""
     config = {'jobid': self.job.id}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [_, loss_map] = maps
     self.assertEqual("loss_map", loss_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (
             0, "RESULT: (%s, 19.19, 21.21)" % loss_map.id, "")
         process_map(loss_map, config)
         self.assertTrue(loss_map.shapefile_path is None)
         self.assertEqual(19.19, loss_map.min_value)
         self.assertEqual(21.21, loss_map.max_value)
예제 #4
0
 def test_process_map_with_shapefile_and_hazard_to_db(self):
     """The db record for the hazard map is updated."""
     config = {'jobid': self.job.id}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [hazard_map, _] = maps
     self.assertEqual("hazard_map", hazard_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (0, "RESULT: (%s, 17.17, 18.18)" %
                                   hazard_map.id, "")
         process_map(hazard_map, config)
         self.assertTrue(hazard_map.shapefile_path is None)
         self.assertEqual(17.17, hazard_map.min_value)
         self.assertEqual(18.18, hazard_map.max_value)
예제 #5
0
 def test_process_map_with_shapefile_and_hazard_to_db(self):
     """The db record for the hazard map is updated."""
     config = {'jobid': self.job.id}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [hazard_map, _] = maps
     self.assertEqual("hazard_map", hazard_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (
             0, "RESULT: (%s, 17.17, 18.18)" % hazard_map.id, "")
         process_map(hazard_map, config)
         self.assertTrue(hazard_map.shapefile_path is None)
         self.assertEqual(17.17, hazard_map.min_value)
         self.assertEqual(18.18, hazard_map.max_value)
예제 #6
0
 def test_process_map_with_map_transformer_error(self):
     """
     If the shapefile generation fails for a map the db record is *not*
     updated.
     """
     config = {'jobid': self.job.id, 'shapefile': True}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [hazard_map, _] = maps
     self.assertEqual("hazard_map", hazard_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (1, "", "failed to generate shapefile")
         process_map(hazard_map, config)
         self.assertTrue(hazard_map.shapefile_path is None)
         self.assertTrue(hazard_map.min_value is None)
         self.assertTrue(hazard_map.max_value is None)
예제 #7
0
 def test_process_map_with_map_transformer_error(self):
     """
     If the shapefile generation fails for a map the db record is *not*
     updated.
     """
     config = {'jobid': self.job.id, 'shapefile': True}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [hazard_map, _] = maps
     self.assertEqual("hazard_map", hazard_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (
             1, "", "failed to generate shapefile")
         process_map(hazard_map, config)
         self.assertTrue(hazard_map.shapefile_path is None)
         self.assertTrue(hazard_map.min_value is None)
         self.assertTrue(hazard_map.max_value is None)
예제 #8
0
 def test_process_map_calls_map_transformer_correctly_with_loss(self):
     """
     The map transformer is invoked correctly for a loss map that is to be
     written to a shapefile.
     """
     config = {'jobid': self.job.id, 'shapefile': True}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [_, loss_map] = maps
     basename = os.path.basename(loss_map.path)
     self.assertEqual("loss_map", loss_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (
             0, "RESULT: ('/d/e/f', 61.4039544548262, 926.3032629745)", "")
         process_map(loss_map, config)
         args, kwargs = mock_func.call_args
         expected = (
             ['%s/bin/map_transformer.py' % settings.OQ_APIAPP_DIR,
              '-k', str(loss_map.id),
              '-p', '%s/computed_output/%s' % (self.job.path, basename),
              '--shapefile', '-t', 'loss'],)
         self.assertEqual(expected, args)
         self.assertEqual({'ignore_exit_code': True}, kwargs)
예제 #9
0
 def test_process_map_calls_map_transformer_correctly_with_hazard(self):
     """
     The map transformer is invoked correctly for a hazard map that is to be
     written to a shapefile.
     """
     config = {'jobid': self.job.id, 'shapefile': True}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [hazard_map, _] = maps
     basename = os.path.basename(hazard_map.path)
     self.assertEqual("hazard_map", hazard_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (
             0, "RESULT: ('/a/b/c', 16.04934554846202, 629.323267954)", "")
         process_map(hazard_map, config)
         args, kwargs = mock_func.call_args
         expected = (
             ['%s/bin/map_transformer.py' % settings.OQ_APIAPP_DIR,
              '-k', str(hazard_map.id),
              '-p', '%s/computed_output/%s' % (self.job.path, basename),
              '--shapefile', '-t', 'hazard'],)
         self.assertEqual(expected, args)
         self.assertEqual({'ignore_exit_code': True}, kwargs)
예제 #10
0
 def test_process_map_calls_map_transformer_correctly_with_loss(self):
     """
     The map transformer is invoked correctly for a loss map that is to be
     written to a shapefile.
     """
     config = {'jobid': self.job.id, 'shapefile': True}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [_, loss_map] = maps
     basename = os.path.basename(loss_map.path)
     self.assertEqual("loss_map", loss_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (
             0, "RESULT: ('/d/e/f', 61.4039544548262, 926.3032629745)", "")
         process_map(loss_map, config)
         args, kwargs = mock_func.call_args
         expected = ([
             '%s/bin/map_transformer.py' % settings.OQ_APIAPP_DIR, '-k',
             str(loss_map.id), '-p',
             '%s/computed_output/%s' % (self.job.path, basename),
             '--shapefile', '-t', 'loss'
         ], )
         self.assertEqual(expected, args)
         self.assertEqual({'ignore_exit_code': True}, kwargs)
예제 #11
0
 def test_process_map_calls_map_transformer_correctly_with_hazard(self):
     """
     The map transformer is invoked correctly for a hazard map that is to be
     written to a shapefile.
     """
     config = {'jobid': self.job.id, 'shapefile': True}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [hazard_map, _] = maps
     basename = os.path.basename(hazard_map.path)
     self.assertEqual("hazard_map", hazard_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (
             0, "RESULT: ('/a/b/c', 16.04934554846202, 629.323267954)", "")
         process_map(hazard_map, config)
         args, kwargs = mock_func.call_args
         expected = ([
             '%s/bin/map_transformer.py' % settings.OQ_APIAPP_DIR, '-k',
             str(hazard_map.id), '-p',
             '%s/computed_output/%s' % (self.job.path, basename),
             '--shapefile', '-t', 'hazard'
         ], )
         self.assertEqual(expected, args)
         self.assertEqual({'ignore_exit_code': True}, kwargs)
예제 #12
0
 def test_process_map_calls_map_transformer_correctly_with_loss_to_db(self):
     """
     The map transformer is invoked correctly for a loss map that is to be
     written to the database.
     Specifically: the '--shapefile' command line argument is not supplied.
     """
     config = {'jobid': self.job.id}
     maps = find_maps(self.job)
     self.assertEqual(2, len(maps))
     [_, loss_map] = maps
     basename = os.path.basename(loss_map.path)
     self.assertEqual("loss_map", loss_map.output_type)
     with mock.patch('geonode.mtapi.view_utils.run_cmd') as mock_func:
         mock_func.return_value = (
             0, "RESULT: (%s, 19.19, 21.21)" % loss_map.id, "")
         process_map(loss_map, config)
         args, kwargs = mock_func.call_args
         expected = (
             ['%s/bin/map_transformer.py' % settings.OQ_APIAPP_DIR,
              '-k', str(loss_map.id),
              '-p', '%s/computed_output/%s' % (self.job.path, basename),
              '-t', 'loss'],)
         self.assertEqual(expected, args)
         self.assertEqual({'ignore_exit_code': True}, kwargs)