Skip to content

Commit

Permalink
Fix asset build
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed May 8, 2024
1 parent e8713cb commit e9d8ced
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 7 additions & 5 deletions importer/handlers/common/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 10 additions & 7 deletions importer/tests/unit/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
},
Expand Down

0 comments on commit e9d8ced

Please sign in to comment.