From c404bf34866cc015790cbfd0cd133e09d99d1b77 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 22 Jan 2020 19:52:48 +0100 Subject: [PATCH] visualization: handle empty geolocation measure (#39180) --- bijoe/visualization/views.py | 3 +- tests/test_schema1.py | 56 +++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/bijoe/visualization/views.py b/bijoe/visualization/views.py index e07cc0f..8271803 100644 --- a/bijoe/visualization/views.py +++ b/bijoe/visualization/views.py @@ -268,11 +268,12 @@ class VisualizationGeoJSONView(generics.GenericAPIView): properties = {} for cell in row.dimensions: properties[cell.dimension.label] = '%s' % (cell,) + points = row.measures[0].value or [] geojson.append({ 'type': 'Feature', 'geometry': { 'type': 'MultiPoint', - 'coordinates': [[coord for coord in point] for point in row.measures[0].value], + 'coordinates': [[coord for coord in point] for point in points], }, 'properties': properties, }) diff --git a/tests/test_schema1.py b/tests/test_schema1.py index 5788034..6f53b16 100644 --- a/tests/test_schema1.py +++ b/tests/test_schema1.py @@ -235,39 +235,69 @@ def test_geoloc(schema1, app, admin): 'cube': 'facts1', 'representation': 'graphical', 'measure': 'percent', - 'drilldown_y': 'leftcategory', + 'drilldown_y': 'outercategory', 'drilldown_x': 'date__year', }) response = app.get('/visualization/%d/geojson/' % visu.pk) assert response.json == [ { - u'geometry': - { + 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], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], - [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], - [1.0, 1.0] + [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], + [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], + [1.0, 1.0], [1.0, 1.0], [1.0, 1.0], [1.0, 1.0] ], u'type': u'MultiPoint' }, u'properties': { - u'Left Category': u'cat\xe91', + u'Outer Category': u'cat\xe91', u'ann\xe9e (Date)': u'2017' }, - u'type': u'Feature', + u'type': u'Feature' }, { u'geometry': { - u'coordinates': [ - [1.0, 1.0] - ], + u'coordinates': [[1.0, 1.0]], u'type': u'MultiPoint' }, u'properties': { - u'Left Category': u'Aucun(e)', + u'Outer Category': u'Aucun(e)', u'ann\xe9e (Date)': u'2017' }, u'type': u'Feature' + }, + { + u'geometry': { + u'coordinates': [], + u'type': u'MultiPoint' + }, + u'properties': { + u'Outer Category': u'cat\xe92', + u'ann\xe9e (Date)': u'Aucun(e)' + }, + u'type': u'Feature' + }, + { + u'geometry': { + u'coordinates': [], + u'type': u'MultiPoint' + }, + u'properties': { + u'Outer Category': u'cat\xe93', + u'ann\xe9e (Date)': u'Aucun(e)' + }, + u'type': u'Feature' + }, + { + u'geometry': { + u'coordinates': [], + u'type': u'MultiPoint' + }, + u'properties': { + u'Outer Category': u'cat\xe91', + u'ann\xe9e (Date)': u'Aucun(e)' + }, + u'type': u'Feature' } ] + -- 2.24.0