Skip to content

Commit

Permalink
[Fixes #10113] Data retriver keep kmz files even if is unzipped (#10114
Browse files Browse the repository at this point in the history
…) (#10115)

* [Fixes #10113] Data retriever keeps kmz files even if are unzipped

Co-authored-by: mattiagiupponi <51856725+mattiagiupponi@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and mattiagiupponi committed Oct 10, 2022
1 parent 9e95133 commit a3cf8b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
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.

0 comments on commit a3cf8b2

Please sign in to comment.