summaryrefslogtreecommitdiff
path: root/tests/gis_tests
diff options
context:
space:
mode:
authorSamir Shah <solaris.smoke@gmail.com>2022-05-28 12:33:15 +0300
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-06-01 19:11:26 +0200
commit6f73eb9d90cfec684529aab48d517e3d6449ba8c (patch)
tree4c25ff654a55ac837acc0621c8e473d4093f5d8d /tests/gis_tests
parent9a3b7e5e2be751d28b8782ad23a63e1c75f27e24 (diff)
downloaddjango-6f73eb9d90cfec684529aab48d517e3d6449ba8c.tar.gz
Fixed #33742 -- Added id to GeoJSON serializer.
Diffstat (limited to 'tests/gis_tests')
-rw-r--r--tests/gis_tests/geoapp/test_serializers.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/gis_tests/geoapp/test_serializers.py b/tests/gis_tests/geoapp/test_serializers.py
index 44066daee9..ecff6e6471 100644
--- a/tests/gis_tests/geoapp/test_serializers.py
+++ b/tests/gis_tests/geoapp/test_serializers.py
@@ -27,6 +27,7 @@ class GeoJSONSerializerTests(TestCase):
self.assertEqual(geodata["features"][0]["geometry"]["type"], "Point")
self.assertEqual(geodata["features"][0]["properties"]["name"], "Chicago")
first_city = City.objects.order_by("name").first()
+ self.assertEqual(geodata["features"][0]["id"], first_city.pk)
self.assertEqual(geodata["features"][0]["properties"]["pk"], str(first_city.pk))
def test_geometry_field_option(self):
@@ -61,6 +62,17 @@ class GeoJSONSerializerTests(TestCase):
geodata = json.loads(geojson)
self.assertEqual(geodata["features"][0]["geometry"]["type"], "Polygon")
+ def test_id_field_option(self):
+ """
+ By default Django uses the pk of the object as the id for a feature.
+ The 'id_field' option can be used to specify a different field to use
+ as the id.
+ """
+ cities = City.objects.order_by("name")
+ geojson = serializers.serialize("geojson", cities, id_field="name")
+ geodata = json.loads(geojson)
+ self.assertEqual(geodata["features"][0]["id"], cities[0].name)
+
def test_fields_option(self):
"""
The fields option allows to define a subset of fields to be present in