Skip to content

Commit

Permalink
[Fixes #233] add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiagiupponi committed May 3, 2024
1 parent c2aa3f1 commit c817be9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
4 changes: 4 additions & 0 deletions importer/handlers/common/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ def import_resource(self, files: dict, execution_id: str, **kwargs) -> str:
dynamic_model = None
celery_group = None
try:
if len(layers) == 0:
raise Exception("No valid layers found")

# start looping on the layers available

for index, layer in enumerate(layers, start=1):
layer_name = self.fixup_name(layer.GetName())

Expand Down
34 changes: 34 additions & 0 deletions importer/tests/end2end/test_end2end.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,40 @@ def test_import_geopackage_with_no_crs_table(self):
if layer:
self.cat.delete(layer)

@override_settings(ASYNC_SIGNALS=False)
@mock.patch.dict(os.environ, {"GEONODE_GEODATABASE": "test_geonode_data"})
@override_settings(
GEODATABASE_URL=f"{geourl.split('/geonode_data')[0]}/test_geonode_data"
)
@mock.patch(
"importer.handlers.common.vector.BaseVectorFileHandler._select_valid_layers"
)
def test_import_geopackage_with_no_crs_table_should_raise_error_if_all_layer_are_invalid(
self, _select_valid_layers
):
_select_valid_layers.return_value = []
layer = self.cat.get_layer("geonode:mattia_test")
if layer:
self.cat.delete(layer)

payload = {
"base_file": open(self.no_crs_gpkg, "rb"),
}

with self.assertLogs(level="ERROR") as _log:
self.client.force_login(self.admin)

response = self.client.post(self.url, data=payload)
self.assertEqual(500, response.status_code)

self.assertIn(
"No valid layers found",
[x.message for x in _log.records],
)
layer = self.cat.get_layer("geonode:mattia_test")
if layer:
self.cat.delete(layer)


class ImporterGeoJsonImportTest(BaseImporterEndToEndTest):
@mock.patch.dict(os.environ, {"GEONODE_GEODATABASE": "test_geonode_data"})
Expand Down

0 comments on commit c817be9

Please sign in to comment.