Skip to content

Commit

Permalink
only validate geometry if there is any
Browse files Browse the repository at this point in the history
  • Loading branch information
kshitijrajsharma committed Dec 26, 2023
1 parent 8e8b8b4 commit 395e73d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/validation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,24 @@ class GeometryValidatorMixin:
@validator("geometry")
def validate_geometry(cls, value):
"""Validates geometry"""
if value.type == "Feature":
if value.geometry.type not in ["Polygon", "Multipolygon"]:
raise ValueError(
f"Feature geometry type {value.geometry.type} must be of type polygon/multipolygon",
)
return value.geometry
if value.type == "FeatureCollection":
for feature in value.features:
if feature.geometry.type not in ["Polygon", "MultiPolygon"]:
if value:
if value.type == "Feature":
if value.geometry.type not in ["Polygon", "Multipolygon"]:
raise ValueError(
f"Feature Collection can't have {feature.type} , should be polygon/multipolygon"
f"Feature geometry type {value.geometry.type} must be of type polygon/multipolygon",
)
if len(value.features) > 1:
raise ValueError(
"Feature collection with multiple features is not supported yet"
)
return value.features[0].geometry
return value.geometry
if value.type == "FeatureCollection":
for feature in value.features:
if feature.geometry.type not in ["Polygon", "MultiPolygon"]:
raise ValueError(
f"Feature Collection can't have {feature.type} , should be polygon/multipolygon"
)
if len(value.features) > 1:
raise ValueError(
"Feature collection with multiple features is not supported yet"
)
return value.features[0].geometry
return value


Expand Down
1 change: 1 addition & 0 deletions tests/test_API.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@ def test_hdx_submit_normal_iso3_upload_option():
headers = {"access-token": access_token}
payload = {
"iso3": "NPL",
"hdx_upload": "true",
"categories": [
{
"Roads": {
Expand Down

0 comments on commit 395e73d

Please sign in to comment.