Skip to content

Commit

Permalink
Skip parking payzones with no geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
japauliina authored and mhieta committed Feb 15, 2024
1 parent 63be0a3 commit ae31fc8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
15 changes: 10 additions & 5 deletions services/management/commands/update_vantaa_parking_payzones.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,21 @@ def update_parking_payzones(self):

updated_parking_payzones = []
for feature in features:
geom = MultiPolygon(
GEOSGeometry(str(feature.get("geometry")), srid=SRC_SRID)
)
geom.transform(src_to_dest)
props = feature.get("properties")
name_fi = props.get("maksullisu")
geometry = feature.get("geometry")

if not geometry:
logger.warning(f"Parking payzone {name_fi} has no geometry, skipping")
continue

geom = MultiPolygon(GEOSGeometry(str(geometry), srid=SRC_SRID))
geom.transform(src_to_dest)

origin_id = str(props.get("objectid")) if props.get("objectid") else None
if not origin_id:
logger.warning("Parking payzone has no origin ID, skipping")
continue
name_fi = props.get("maksullisu")

defaults = {
"name_fi": name_fi,
Expand Down
17 changes: 17 additions & 0 deletions services/tests/data/vantaa_parking_payzones_null_geometry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"features": [
{
"geometry": null,
"id": 3,
"properties": {
"maksullisu": "3 € / tunti",
"objectid": 3
},
"type": "Feature"
}
],
"properties": {
"exceededTransferLimit": false
},
"type": "FeatureCollection"
}
21 changes: 19 additions & 2 deletions services/tests/test_update_vantaa_parking_payzones.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
)


def get_mock_data():
file_path = "services/tests/data/vantaa_parking_payzones.json"
def get_mock_data(geometry=True):
if geometry:
file_path = "services/tests/data/vantaa_parking_payzones.json"
else:
file_path = "services/tests/data/vantaa_parking_payzones_null_geometry.json"
with open(file_path, "r") as json_file:
contents = json.load(json_file)
return contents.get("features")
Expand Down Expand Up @@ -89,3 +92,17 @@ def test_delete_removed_parking_payzones(get_features_mock):
== 2
)
assert not AdministrativeDivision.objects.filter(origin_id="3").exists()


@pytest.mark.django_db
@patch(
"services.management.commands.update_vantaa_parking_payzones.Command.get_features"
)
def test_skip_parking_payzone_with_no_geometry(get_features_mock):
get_features_mock.return_value = get_mock_data(geometry=False)
Municipality.objects.create(id="vantaa", name="Vantaa")
AdministrativeDivisionType.objects.create(type="parking_payzone")

assert AdministrativeDivision.objects.count() == 0
call_command("update_vantaa_parking_payzones")
assert AdministrativeDivision.objects.count() == 0

0 comments on commit ae31fc8

Please sign in to comment.