Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #10113] Data retriver keep kmz files even if is unzipped #10114

Merged
merged 5 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion geonode/storage/data_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _unzip(self, zip_name: str) -> Mapping:
the_zip = zipfile.ZipFile(zip_file, allowZip64=True)
the_zip.extractall(self.temporary_folder)
available_choices = get_allowed_extensions()
not_main_files = ['xml', 'sld', 'zip']
not_main_files = ['xml', 'sld', 'zip', 'kmz']
base_file_choices = [x for x in available_choices if x not in not_main_files]
for _file in Path(self.temporary_folder).iterdir():
if any([_file.name.endswith(_ext) for _ext in base_file_choices]):
Expand Down
21 changes: 21 additions & 0 deletions geonode/storage/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io
import os
import shutil
from django.test import override_settings
import gisdata
from unittest.mock import patch

Expand Down Expand Up @@ -584,6 +585,26 @@ def test_zip_file_should_correctly_recognize_main_extension_with_csv(self):
_files = storage_manager.get_retrieved_paths()
self.assertTrue("example.csv" in _files.get("base_file"))

@override_settings(SUPPORTED_DATASET_FILE_TYPES=[{
"id": "kmz",
"label": "kmz",
"format": "vector",
"ext": ["kmz"]
}, {
"id": "kml",
"label": "kml",
"format": "vector",
"ext": ["kml"]
}])
def test_zip_file_should_correctly_recognize_main_extension_with_kmz(self):
# reinitiate the storage manager with the zip file
storage_manager = self.sut(remote_files={"base_file": os.path.join(f"{self.project_root}", "tests/data/Italy.kmz")})
storage_manager.clone_remote_files()

self.assertIsNotNone(storage_manager.data_retriever.temporary_folder)
_files = storage_manager.get_retrieved_paths()
self.assertTrue("doc.kml" in _files.get("base_file"), msg=f"files available: {_files}")

def test_zip_file_should_correctly_recognize_main_extension_with_shp(self):
# zipping files
storage_manager = self.sut(remote_files=self.local_files_paths)
Expand Down
Binary file added geonode/storage/tests/data/Italy.kmz
Binary file not shown.