Projet

Général

Profil

0002-views-use-FeatureCollection-for-geojson-format-51163.patch

Serghei Mihai (congés, retour 15/05), 16 février 2021 11:09

Télécharger (2,67 ko)

Voir les différences:

Subject: [PATCH 2/2] 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(-)
bijoe/visualization/views.py
284 284
        instance = self.get_object()
285 285
        visualization = Visualization.from_json(instance.parameters)
286 286
        visualization.measure = visualization.cube.measures['geolocation']
287
        geojson = []
287
        geojson = {'type': 'FeatureCollection', 'features': []}
288 288

  
289 289
        for row in visualization.data():
290 290
            properties = {}
291 291
            for cell in row.dimensions:
292 292
                properties[cell.dimension.label] = '%s' % (cell,)
293 293
            points = row.measures[0].value or []
294
            geojson.append({
294
            geojson['features'].append({
295 295
                'type': 'Feature',
296 296
                'geometry': {
297 297
                    'type': 'MultiPoint',
tests/test_schema1.py
260 260
            'drilldown_x': 'date__year',
261 261
        })
262 262
    response = app.get('/visualization/%d/geojson/' % visu.pk)
263
    assert response.json == [
264
        {
263
    assert response.json == {
264
        'type': 'FeatureCollection',
265
        'features': [{
265 266
            u'geometry': {
266 267
                u'coordinates': [
267 268
                    [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 321
            },
321 322
            u'type': u'Feature'
322 323
        }
323
    ]
324
    ]}
324 325

  
325 326

  
326 327
def test_filter_type_mismatch(schema1, app, admin):
tests/test_views.py
278 278
    login(app, admin)
279 279
    resp = app.get('/visualization/%s/geojson/' % visualization.id)
280 280
    assert resp.content_type == 'application/json'
281
    assert len(resp.json) == 8
281
    assert resp.json['type'] == 'FeatureCollection'
282
    assert len(resp.json['features']) == 8
282 283

  
283 284

  
284 285
@mock.patch('bijoe.views.get_idps', return_value=[{'METADATA': '...'}])
285
-