Projet

Général

Profil

0001-data_source-handle-err-in-JSON-output-41195.patch

Thomas Noël, 31 mars 2020 14:47

Télécharger (2,51 ko)

Voir les différences:

Subject: [PATCH] data_source: handle err in JSON output (#41195)

 tests/test_datasource.py | 4 ++++
 tests/utilities.py       | 1 +
 wcs/data_sources.py      | 2 ++
 3 files changed, 7 insertions(+)
tests/test_datasource.py
296 296
    assert 'Error loading JSON data source' in caplog.records[-1].message
297 297
    assert 'error' in caplog.records[-1].message
298 298

  
299
    datasource = {'type': 'json', 'value': 'http://remote.example.net/json-list-err1'}
300
    assert data_sources.get_items(datasource) == []
301
    assert 'Error reading JSON data source output (err 1)' in caplog.records[-1].message
302

  
299 303

  
300 304
def test_json_datasource_bad_url_scheme(caplog):
301 305
    datasource = {'type': 'json', 'value': ''}
tests/utilities.py
329 329
            'http://remote.example.net/json-list': (200, '{"data": [{"id": "a", "text": "b"}]}', None),
330 330
            'http://remote.example.net/json-err0': (200, '{"data": "foo", "err": 0}', None),
331 331
            'http://remote.example.net/json-err1': (200, '{"data": "", "err": 1}', None),
332
            'http://remote.example.net/json-list-err1': (200, '{"data": [{"id": "a", "text": "b"}], "err": 1}', None),
332 333
            'http://remote.example.net/json-errstr': (200, '{"data": "", "err": "bug"}', None),
333 334
            'http://remote.example.net/json-errheader0': (200, '{"foo": "bar"}',
334 335
                                              {'x-error-code': '0'}),
wcs/data_sources.py
201 201
            entries = misc.json_loads(misc.urlopen(url).read())
202 202
            if type(entries) is not dict:
203 203
                raise ValueError('not a json dict')
204
            if entries.get('err') and entries['err'] not in (0, "0"):
205
                raise ValueError('err %s' % entries['err'])
204 206
            if type(entries.get('data')) is not list:
205 207
                raise ValueError('not a json dict with a data list attribute')
206 208
            items = []
207
-