Skip to content

Commit fe0f319

Browse files
[Fixes #14366] Upload error message (#14370)
* [Fixes #14366] Upload error message * Update geonode/upload/handlers/shapefile/handler.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update geonode/upload/handlers/shapefile/tests.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent a1f0c2d commit fe0f319

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

geonode/upload/handlers/shapefile/handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def is_valid(files, user, **kwargs):
156156
)
157157
if not is_valid:
158158
raise InvalidShapeFileException(
159-
detail=f"Some file is missing files with the same name and with the following extension are required: {_shp_ext_needed}"
159+
detail=f"Some files are missing. The files need to have the same name with all extensions: {', '.join(ShapeFileHandler._get_ext_needed())}"
160160
)
161161

162162
return True

geonode/upload/handlers/shapefile/tests.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from django.contrib.auth import get_user_model
2626
from django.test import TestCase
2727
from geonode.upload.api.exceptions import UploadParallelismLimitException
28+
from geonode.upload.handlers.shapefile.exceptions import InvalidShapeFileException
2829
from geonode.upload.models import UploadParallelismLimit
2930
from mock import MagicMock, patch, mock_open
3031
from geonode.upload import project_dir
@@ -108,6 +109,17 @@ def test_promote_to_multi(self):
108109
def test_is_valid_should_pass_with_valid_shp(self):
109110
self.handler.is_valid(files=self.valid_shp, user=self.user)
110111

112+
def test_is_valid_should_not_pass_if_file_is_missing(self):
113+
files = self.valid_shp.copy()
114+
files.pop("dbf_file")
115+
with self.assertRaises(InvalidShapeFileException) as _exp:
116+
self.handler.is_valid(files=files, user=self.user)
117+
self.assertIn(
118+
"Some files are missing. The files need to have the same name with all extensions: shp, prj, dbf, shx",
119+
str(_exp.exception),
120+
"error message is not the expected one",
121+
)
122+
111123
def test_get_ogr2ogr_driver_should_return_the_expected_driver(self):
112124
expected = ogr.GetDriverByName("ESRI Shapefile")
113125
actual = self.handler.get_ogr2ogr_driver()

0 commit comments

Comments
 (0)