From e9d8ced5209874f45f0127758f7e78e315a103ef Mon Sep 17 00:00:00 2001 From: mattiagiupponi Date: Wed, 8 May 2024 12:08:52 +0200 Subject: [PATCH] Fix asset build --- importer/handlers/common/vector.py | 12 +++++++----- importer/tests/unit/test_task.py | 17 ++++++++++------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/importer/handlers/common/vector.py b/importer/handlers/common/vector.py index 17af9004..345893b6 100644 --- a/importer/handlers/common/vector.py +++ b/importer/handlers/common/vector.py @@ -31,7 +31,7 @@ from importer.api.exception import ImportException from importer.celery_app import importer_app from geonode.storage.manager import storage_manager -from geonode.assets.utils import copy_assets_and_links +from geonode.assets.utils import copy_assets_and_links, get_default_asset from importer.handlers.utils import create_alternate, should_be_imported from importer.models import ResourceHandlerInfo @@ -245,10 +245,12 @@ def perform_last_step(execution_id): _exec.save() if _exec and not _exec.input_params.get("store_spatial_file", False): resources = ResourceHandlerInfo.objects.filter(execution_request=_exec) - # getting all files list - resources_files = list(set(chain(*[x.resource.files for x in resources]))) - # better to delete each single file since it can be a remove storage service - list(map(storage_manager.delete, resources_files)) + # getting all assets list + assets = [get_default_asset(x.resource) for x in resources] + # we need to loop and cancel one by one to activate the signal + # which delete the file from the filesystem + for asset in assets: + asset.delete() def extract_resource_to_publish( self, files, action, layer_name, alternate, **kwargs diff --git a/importer/tests/unit/test_task.py b/importer/tests/unit/test_task.py index c9b599f9..8ea4c955 100644 --- a/importer/tests/unit/test_task.py +++ b/importer/tests/unit/test_task.py @@ -27,6 +27,7 @@ from dynamic_models.models import ModelSchema, FieldSchema from dynamic_models.exceptions import DynamicModelError, InvalidFieldNameError from importer.models import ResourceHandlerInfo +from importer import project_dir from importer.tests.utils import ( ImporterBaseTestSupport, @@ -39,13 +40,14 @@ class TestCeleryTasks(ImporterBaseTestSupport): def setUp(self): self.user = get_user_model().objects.first() + self.existing_file = f"{project_dir}/tests/fixture/valid.gpkg" self.exec_id = orchestrator.create_execution_request( user=get_user_model().objects.get(username=self.user), func_name="dummy_func", step="dummy_step", legacy_upload_name="dummy", input_params={ - "files": {"base_file": "/filepath"}, + "files": {"base_file": self.existing_file}, # "overwrite_existing_layer": True, "store_spatial_files": True, }, @@ -82,7 +84,7 @@ def test_import_resource_should_rase_exp_if_is_invalid( func_name="dummy_func", step="dummy_step", legacy_upload_name="dummy", - input_params={"files": "/filepath", "store_spatial_files": True}, + input_params={"files": self.existing_file, "store_spatial_files": True}, ) is_valid.side_effect = Exception("Invalid format type") @@ -116,7 +118,7 @@ def test_import_resource_should_work( func_name="dummy_func", step="dummy_step", legacy_upload_name="dummy", - input_params={"files": "/filepath", "store_spatial_files": True}, + input_params={"files": self.existing_file, "store_spatial_files": True}, ) import_resource( @@ -189,7 +191,7 @@ def test_publish_resource_if_overwrite_should_call_the_publishing( step="dummy_step", legacy_upload_name="dummy", input_params={ - "files": {"base_file": "/filepath"}, + "files": {"base_file": self.existing_file}, "overwrite_existing_layer": True, "store_spatial_files": True, }, @@ -244,7 +246,7 @@ def test_publish_resource_if_overwrite_should_not_call_the_publishing( step="dummy_step", legacy_upload_name="dummy", input_params={ - "files": {"base_file": "/filepath"}, + "files": {"base_file": self.existing_file}, "overwrite_existing_layer": True, "store_spatial_files": True, }, @@ -388,7 +390,7 @@ def test_rollback_works_as_expected_vector_step( step=conf[0], # step name action="import", input_params={ - "files": {"base_file": "/filepath"}, + "files": {"base_file": self.existing_file}, "overwrite_existing_layer": True, "store_spatial_files": True, "handler_module_path": "importer.handlers.gpkg.handler.GPKGFileHandler", @@ -509,13 +511,14 @@ class TestDynamicModelSchema(TransactionImporterBaseTestSupport): def setUp(self): self.user = get_user_model().objects.first() + self.existing_file = f"{project_dir}/tests/fixture/valid.gpkg" self.exec_id = orchestrator.create_execution_request( user=get_user_model().objects.get(username=self.user), func_name="dummy_func", step="dummy_step", legacy_upload_name="dummy", input_params={ - "files": {"base_file": "/filepath"}, + "files": {"base_file": self.existing_file}, # "overwrite_existing_layer": True, "store_spatial_files": True, },