0001-datasources-skip-json-entries-where-text-value-is-no.patch
tests/test_datasource.py | ||
---|---|---|
330 | 330 |
assert data_sources.get_items(datasource) == [] |
331 | 331 |
assert data_sources.get_structured_items(datasource) == [] |
332 | 332 | |
333 |
# a json file with invalid datatype for the text entry, (list in text key), |
|
334 |
# the invalid entry will be skipped |
|
335 |
get_request().datasources_cache = {} |
|
336 |
with open(json_file_path, 'w') as json_file: |
|
337 |
json.dump({'data': [{'id': '1', 'text': ['foo']}, {'id': '2', 'text': 'bar'}]}, json_file) |
|
338 |
assert data_sources.get_items(datasource) == [('2', 'bar', '2', {'id': '2', 'text': 'bar'})] |
|
339 |
assert data_sources.get_structured_items(datasource) == [{'id': '2', 'text': 'bar'}] |
|
340 | ||
333 | 341 |
# specify data_attribute |
334 | 342 |
datasource = {'type': 'json', 'value': ' {{ json_url }}', 'data_attribute': 'results'} |
335 | 343 |
get_request().datasources_cache = {} |
wcs/data_sources.py | ||
---|---|---|
233 | 233 |
item['text'] = str(item['id']) |
234 | 234 |
else: |
235 | 235 |
item['text'] = item[text_attribute] |
236 |
if not isinstance(item['text'], str): |
|
237 |
continue |
|
236 | 238 |
items.append(item) |
237 | 239 |
return items |
238 | 240 | |
239 |
- |