diff --git a/georest/__init__.py b/georest/__init__.py index 34fb9f2..e76fbc8 100644 --- a/georest/__init__.py +++ b/georest/__init__.py @@ -376,11 +376,10 @@ def _get_store_name_from_filename(config, fname): if "layer_id" in config: layer_id = file_parts[config["layer_id"]] return config["layers"][layer_id] - elif "layer_name_template" in config: + if "layer_name_template" in config: layer_name = trollsift.compose(config["layer_name_template"], file_parts) return layer_name - else: - raise ValueError("Either 'layer_id' or 'layer_name_template' must be defined in config") + raise ValueError("Either 'layer_id' or 'layer_name_template' must be defined in config") def delete_file_from_mosaic(config, fname): diff --git a/georest/tests/test_geoserver.py b/georest/tests/test_geoserver.py index 33b2679..9546cd8 100644 --- a/georest/tests/test_geoserver.py +++ b/georest/tests/test_geoserver.py @@ -500,22 +500,27 @@ def test_delete_file_from_mosaic_layertemplate(connect_to_gs_catalog): "geoserver_target_dir": "/mnt/data", "file_pattern": "{area}_{productname}.tif", "layer_name_template": "{productname}_{area}", - "delete_granule_layer_options": {"area": ["europe"], "productname": ["airmass"]}, + "delete_granule_layer_options": {"area": ["europe", "global"], "productname": ["airmass1", "airmass2"]}, } - fname = "europe_airmass.tif" + fnames = ["europe_airmass1.tif", "global_airmass1.tif", "europe_airmass2.tif", "global_airmass2.tif"] - delete_file_from_mosaic(config, fname) + for fname in fnames: + delete_file_from_mosaic(config, fname) connect_to_gs_catalog.assert_called_with(config) - cat.get_store.assert_called_with("airmass_europe", "satellite") + assert cat.get_store.call_count == len(fnames) + assert "call('airmass1_europe', 'satellite')" in str(cat.get_store.call_args_list) + assert "call('airmass2_europe', 'satellite')" in str(cat.get_store.call_args_list) + assert "call('airmass1_global', 'satellite')" in str(cat.get_store.call_args_list) + assert "call('airmass1_global', 'satellite')" in str(cat.get_store.call_args_list) cat.list_granules.assert_called() cat.delete_granule.assert_not_called() # This is the structure returned by cat.list_granules() - granules = {"features": [{"properties": {"location": "/mnt/data/europe_airmass.tif"}, "id": "file-id"}]} + granules = {"features": [{"properties": {"location": "/mnt/data/europe_airmass1.tif"}, "id": "file-id"}]} cat.list_granules.return_value = granules - delete_file_from_mosaic(config, fname) + delete_file_from_mosaic(config, fnames[0]) cat.delete_granule.assert_called() diff --git a/georest/utils.py b/georest/utils.py index 0324d4f..7e289bb 100644 --- a/georest/utils.py +++ b/georest/utils.py @@ -133,17 +133,15 @@ def get_exposed_layer_directories(config): def get_layers_for_delete_granules(config): """Get list of layers for deleting granules.""" if config.get("layer_id", False): - layers = list(config["layers"].values()) - elif config.get("layer_name_template", False) and config.get("delete_granule_layer_options", False): + return list(config["layers"].values()) + if config.get("layer_name_template", False) and config.get("delete_granule_layer_options", False): keys = sorted(config["delete_granule_layer_options"].keys()) combinations = list(itertools.product(*[config["delete_granule_layer_options"][k] for k in keys])) options = [dict(zip(keys, l)) for l in combinations] - layers = [config["layer_name_template"].format(**opt) for opt in options] - else: - raise ValueError( - "Either 'layer_id' or 'layer_name_template' (with 'delete_granule_layer_options') must be defined in config" - ) - return layers + return [config["layer_name_template"].format(**opt) for opt in options] + raise ValueError( + "Either 'layer_id' or 'layer_name_template' (with 'delete_granule_layer_options') must be defined in config" + ) def write_wkt(config, image_fname):