0001-map-don-t-fail-on-invalid-geojson-data-53521.patch
combo/apps/maps/models.py | ||
---|---|---|
226 | 226 |
headers={'accept': 'application/json'}, |
227 | 227 |
) |
228 | 228 |
if not response.ok: |
229 |
return [] |
|
230 |
data = response.json() |
|
229 |
return { |
|
230 |
'type': 'FeatureCollection', |
|
231 |
'features': [], |
|
232 |
'_combo_err_desc': "Bad status code from requested URL", |
|
233 |
} |
|
234 |
try: |
|
235 |
data = response.json() |
|
236 |
except json.JSONDecodeError: |
|
237 |
return { |
|
238 |
'type': 'FeatureCollection', |
|
239 |
'features': [], |
|
240 |
'_combo_err_desc': "Non JSON response from requested URL", |
|
241 |
} |
|
231 | 242 |
if 'features' in data: |
232 | 243 |
features = data['features'] |
233 | 244 |
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 = 200 |
|
292 |
requests_get.return_value = mock_resp |
|
293 |
resp = app.get(geojson_url) |
|
294 |
assert len(resp.json['features']) == 0 |
|
295 |
assert resp.json['_combo_err_desc'] == 'Non JSON response from requested URL' |
|
296 | ||
297 |
mock_resp.status_code = 500 |
|
298 |
resp = app.get(geojson_url) |
|
299 |
assert len(resp.json['features']) == 0 |
|
300 |
assert resp.json['_combo_err_desc'] == 'Bad status code from requested URL' |
|
301 | ||
287 | 302 |
# check cache duration |
288 | 303 |
with mock.patch('combo.utils.requests_wrapper.RequestsSession.request') as requests_get: |
289 | 304 |
requests_get.return_value = mock.Mock( |
290 |
- |