From cac1bc15346e5785c5d808e05a071280fc1eaf41 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Tue, 16 Feb 2021 10:19:26 +0100 Subject: [PATCH] views: use FeatureCollection for geojson format (#51163) --- bijoe/visualization/views.py | 4 ++-- tests/test_schema1.py | 7 ++++--- tests/test_views.py | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bijoe/visualization/views.py b/bijoe/visualization/views.py index 05d18a7..70d4f18 100644 --- a/bijoe/visualization/views.py +++ b/bijoe/visualization/views.py @@ -284,14 +284,14 @@ class VisualizationGeoJSONView(generics.GenericAPIView): instance = self.get_object() visualization = Visualization.from_json(instance.parameters) visualization.measure = visualization.cube.measures['geolocation'] - geojson = [] + geojson = {'type': 'FeatureCollection', 'features': []} for row in visualization.data(): properties = {} for cell in row.dimensions: properties[cell.dimension.label] = '%s' % (cell,) points = row.measures[0].value or [] - geojson.append({ + geojson['features'].append({ 'type': 'Feature', 'geometry': { 'type': 'MultiPoint', diff --git a/tests/test_schema1.py b/tests/test_schema1.py index ae01abc..706ce35 100644 --- a/tests/test_schema1.py +++ b/tests/test_schema1.py @@ -260,8 +260,9 @@ def test_geoloc(schema1, app, admin): 'drilldown_x': 'date__year', }) response = app.get('/visualization/%d/geojson/' % visu.pk) - assert response.json == [ - { + assert response.json == { + 'type': 'FeatureCollection', + 'features': [{ u'geometry': { u'coordinates': [ [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], @@ -320,7 +321,7 @@ def test_geoloc(schema1, app, admin): }, u'type': u'Feature' } - ] + ]} def test_filter_type_mismatch(schema1, app, admin): diff --git a/tests/test_views.py b/tests/test_views.py index 154dec1..908ed85 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -278,7 +278,8 @@ def test_geojson_view(schema1, app, admin, visualization, settings): login(app, admin) resp = app.get('/visualization/%s/geojson/' % visualization.id) assert resp.content_type == 'application/json' - assert len(resp.json) == 8 + assert resp.json['type'] == 'FeatureCollection' + assert len(resp.json['features']) == 8 @mock.patch('bijoe.views.get_idps', return_value=[{'METADATA': '...'}])