Skip to content

Commit 1d57899

Browse files
committed
[qa] Test bounding box calculation when using method field for geo field
1 parent 58ec8d0 commit 1d57899

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

tests/django_restframework_gis_tests/serializers.py

+26
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,32 @@ class Meta:
140140
exclude = []
141141

142142

143+
class LocationGeoFeatureMethodAutoBboxSerializer(gis_serializers.GeoFeatureModelSerializer):
144+
new_geometry = gis_serializers.GeometrySerializerMethodField()
145+
146+
class Meta:
147+
model = Location
148+
geo_field = 'new_geometry'
149+
auto_bbox = True
150+
exclude = []
151+
152+
def get_new_geometry(self, obj):
153+
return obj.geometry
154+
155+
156+
class LocationGeoFeatureMethodManualBboxSerializer(gis_serializers.GeoFeatureModelSerializer):
157+
new_geometry = gis_serializers.GeometrySerializerMethodField()
158+
159+
class Meta:
160+
model = Location
161+
geo_field = 'new_geometry'
162+
bbox_geo_field = 'new_geometry'
163+
exclude = []
164+
165+
def get_new_geometry(self, obj):
166+
return obj.geometry
167+
168+
143169
class NoneGeoFeatureMethodSerializer(gis_serializers.GeoFeatureModelSerializer):
144170
new_geometry = gis_serializers.GeometrySerializerMethodField()
145171

tests/django_restframework_gis_tests/test_bbox.py

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class TestRestFrameworkGisBBox(TestCase):
2222
def setUp(self):
2323
self.geojson_boxedlocation_list_url = reverse('api_geojson_boxedlocation_list')
2424
self.geojson_location_bbox_list_url = reverse('api_geojson_location_bbox_list')
25+
self.geojson_location_method_field_auto_bbox_list_url = reverse('api_geojson_location_method_field_auto_bbox_list')
26+
self.geojson_location_method_field_manual_bbox_list_url = reverse('api_geojson_location_method_field_manual_bbox_list')
2527

2628
def _create_locations(self):
2729
self.bl1 = BoxedLocation.objects.create(
@@ -87,6 +89,20 @@ def test_get_autogenerated_location_bbox_geojson(self):
8789
self.assertEqual(len(response.data['features']), 1)
8890
self.assertEqual(response.data['features'][0]['bbox'], self.l1.geometry.extent)
8991

92+
def test_get_autogenerated_location_auto_bbox_geojson_with_method_field(self):
93+
self._create_locations()
94+
response = self.client.get(self.geojson_location_method_field_auto_bbox_list_url)
95+
self.assertEqual(response.status_code, 200)
96+
self.assertEqual(len(response.data['features']), 1)
97+
self.assertEqual(response.data['features'][0]['bbox'], self.l1.geometry.extent)
98+
99+
def test_get_autogenerated_location_manual_bbox_geojson_with_method_field(self):
100+
self._create_locations()
101+
response = self.client.get(self.geojson_location_method_field_manual_bbox_list_url)
102+
self.assertEqual(response.status_code, 200)
103+
self.assertEqual(len(response.data['features']), 1)
104+
self.assertEqual(response.data['features'][0]['bbox'], self.l1.geometry.extent)
105+
90106
def test_bbox_improperly_configured(self):
91107
self._create_locations()
92108

tests/django_restframework_gis_tests/urls.py

+10
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@
6565
views.geojson_location_bbox_list,
6666
name='api_geojson_location_bbox_list',
6767
),
68+
url(
69+
r'^geojson-location-method-field-auto-bbox/$',
70+
views.geojson_location_method_field_auto_bbox_list,
71+
name='api_geojson_location_method_field_auto_bbox_list',
72+
),
73+
url(
74+
r'^geojson-location-method-field-manual-bbox/$',
75+
views.geojson_location_method_field_manual_bbox_list,
76+
name='api_geojson_location_method_field_manual_bbox_list',
77+
),
6878
# Filters
6979
url(
7080
r'^filters/contained_in_bbox$',

tests/django_restframework_gis_tests/views.py

+20
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
LocationGeoFeatureBboxSerializer,
1919
LocationGeoFeatureFalseIdSerializer,
2020
LocationGeoFeatureMethodSerializer,
21+
LocationGeoFeatureMethodAutoBboxSerializer,
22+
LocationGeoFeatureMethodManualBboxSerializer,
2123
LocationGeoFeatureNoIdSerializer,
2224
LocationGeoFeatureSerializer,
2325
LocationGeoFeatureSlugSerializer,
@@ -240,6 +242,24 @@ class GeojsonLocationBboxList(generics.ListCreateAPIView):
240242
geojson_location_bbox_list = GeojsonLocationBboxList.as_view()
241243

242244

245+
class GeojsonLocationMethodFieldAutoBboxList(generics.ListCreateAPIView):
246+
model = Location
247+
serializer_class = LocationGeoFeatureMethodAutoBboxSerializer
248+
queryset = Location.objects.all()
249+
250+
251+
geojson_location_method_field_auto_bbox_list = GeojsonLocationMethodFieldAutoBboxList.as_view()
252+
253+
254+
class GeojsonLocationMethodFieldManualBboxList(generics.ListCreateAPIView):
255+
model = Location
256+
serializer_class = LocationGeoFeatureMethodManualBboxSerializer
257+
queryset = Location.objects.all()
258+
259+
260+
geojson_location_method_field_manual_bbox_list = GeojsonLocationMethodFieldManualBboxList.as_view()
261+
262+
243263
class GeojsonNullableDetails(generics.RetrieveUpdateDestroyAPIView):
244264
model = Location
245265
serializer_class = LocationGeoFeatureSerializer

0 commit comments

Comments
 (0)