Skip to content

Commit

Permalink
bplan/serializer: add binary=True to point JSONField as we receive a
Browse files Browse the repository at this point in the history
string containing (geo)json, not actual json
  • Loading branch information
goapunk authored and m4ra committed Jan 8, 2025
1 parent b87bc83 commit 669cac7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions docs/bplan_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ The following fields need to be provided:
- End date of the participation in
- [ISO 8601 format](https://en.wikipedia.org/wiki/ISO_8601)
(if no time zone is defined, german time zones UTC+01 and UTC+02 are used)
- *point*: geojson
- *point*: string containing valid geojson
- Location of the bplan
- Projection: WGS84 / EPSG:4326
- *(diplan only) tile_image*: string
Expand Down Expand Up @@ -203,7 +203,7 @@ curl \
"office_worker_email": "[email protected]",
"start_date": "2019-01-01T00:00",
"end_date": "2022-01-01T00:00",
"point": {"type": "Feature","geometry": {"type": "Point", "coordinates":[13.411924777644563,52.499598134440944]}}
"point": "{\"type\": \"Feature\",\"geometry\": {\"type\": \"Point\", \"coordinates\":[13.411924777644563,52.499598134440944]}}"
}
'
```
Expand All @@ -224,7 +224,7 @@ curl -X POST http://127.0.0.1:8003/api/organisations/1/bplan/ \
"office_worker_email": "[email protected]",
"start_date": "2019-01-01T00:00",
"end_date": "2022-01-01T00:00",
"point": {"type": "Feature","geometry": {"type": "Point", "coordinates":[13.411924777644563,52.499598134440944]}}
"point": "{\"type\": \"Feature\",\"geometry\": {\"type\": \"Point\", \"coordinates\":[13.411924777644563,52.499598134440944]}}"
}
'
```
Expand Down
2 changes: 1 addition & 1 deletion meinberlin/apps/bplan/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class BplanSerializer(serializers.ModelSerializer):
)
# overwrite the point model field so it's expecting json, the original field is validated as a string and therefore
# doesn't pass validation when not receiving a string
point = serializers.JSONField(required=False, write_only=True)
point = serializers.JSONField(required=False, write_only=True, binary=True)

class Meta:
model = Bplan
Expand Down
24 changes: 12 additions & 12 deletions tests/bplan/test_bplan_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def test_bplan_api_diplan_adds_district_from_bplan_id(
"office_worker_email": "[email protected]",
"start_date": "2013-01-01 18:00",
"bplan_id": "1-234",
"point": "0,0",
"point": '{"type":"Feature", "geometry":{"type":"Point","coordinates":[13.397788148643649,52.52958586909979]}}',
"end_date": "2021-01-01 18:00",
}
user = organisation.initiators.first()
Expand Down Expand Up @@ -464,7 +464,7 @@ def test_bplan_api_location_task_not_called_if_point_included(
"end_date": "2021-01-01 18:00",
"identifier": "1-234",
"is_published": True,
"point": "[0,0]",
"point": '{"type":"Feature", "geometry":{"type":"Point","coordinates":[13.397788148643649,52.52958586909979]}}',
}
user = organisation.initiators.first()
apiclient.force_authenticate(user=user)
Expand All @@ -474,7 +474,13 @@ def test_bplan_api_location_task_not_called_if_point_included(
bplan = bplan_models.Bplan.objects.first()
assert bplan.is_draft is False
assert bplan.is_diplan is True
assert bplan.point == "[0,0]"
assert bplan.point == {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [13.397788148643649, 52.52958586909979],
},
}
mock.assert_not_called()


Expand All @@ -491,13 +497,7 @@ def test_bplan_api_accepts_valid_geojson(
"end_date": "2021-01-01 18:00",
"identifier": "1-234",
"is_published": True,
"point": {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [13.411924777644563, 52.499598134440944],
},
},
"point": '{"type":"Feature", "geometry":{"type":"Point","coordinates":[13.397788148643649,52.52958586909979]}}',
}
user = organisation.initiators.first()
apiclient.force_authenticate(user=user)
Expand All @@ -511,7 +511,7 @@ def test_bplan_api_accepts_valid_geojson(
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [13.411924777644563, 52.499598134440944],
"coordinates": [13.397788148643649, 52.52958586909979],
},
}

Expand All @@ -530,7 +530,7 @@ def test_bplan_api_accepts_valid_base64_image(
"end_date": "2021-01-01 18:00",
"identifier": "1-234",
"is_published": True,
"point": "1492195.544958444,6895923.461738203",
"point": '{"type":"Feature", "geometry":{"type":"Point","coordinates":[13.397788148643649,52.52958586909979]}}',
"tile_image": image,
}

Expand Down

0 comments on commit 669cac7

Please sign in to comment.