Projet

Général

Profil

0001-map-don-t-fail-on-invalid-geojson-data-53521.patch

Lauréline Guérin, 29 avril 2021 09:46

Télécharger (1,97 ko)

Voir les différences:

Subject: [PATCH] map: don't fail on invalid geojson data (#53521)

 combo/apps/maps/models.py | 5 ++++-
 tests/test_maps_cells.py  | 9 +++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
combo/apps/maps/models.py
227 227
        )
228 228
        if not response.ok:
229 229
            return []
230
        data = response.json()
230
        try:
231
            data = response.json()
232
        except json.JSONDecodeError:
233
            return []
231 234
        if 'features' in data:
232 235
            features = data['features']
233 236
        else:
tests/test_maps_cells.py
7 7
from django.contrib.auth.models import Group, User
8 8
from django.test.client import RequestFactory
9 9
from django.urls import reverse
10
from requests.models import Response
10 11

  
11 12
from combo.apps.maps.models import Map, MapLayer, MapLayerOptions
12 13
from combo.data.models import Page
......
284 285

  
285 286
    geojson_url = reverse('mapcell-geojson', kwargs={'cell_id': cell.id, 'layer_slug': layer.slug})
286 287

  
288
    # invalid content
289
    with mock.patch('combo.utils.requests_wrapper.RequestsSession.get') as requests_get:
290
        mock_resp = Response()
291
        mock_resp.status_code = 300
292
        requests_get.return_value = mock_resp
293
        resp = app.get(geojson_url)
294
        assert resp.json == []
295

  
287 296
    # check cache duration
288 297
    with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get:
289 298
        requests_get.return_value = mock.Mock(
290
-