data_sources: do not crash on unknown source type (#36037)
gitea-wip/wcs/pipeline/head There was a failure building this commit Details
gitea/wcs/pipeline/head Build started... Details

This commit is contained in:
Paul Marillonnet 2019-09-11 14:49:34 +02:00
parent 510a02d416
commit 1b3955253d
2 changed files with 10 additions and 1 deletions

View File

@ -285,6 +285,12 @@ def test_json_datasource_bad_url(http_requests, caplog):
assert 'Error loading JSON data source' in caplog.records[-1].message
assert 'error' in caplog.records[-1].message
def test_json_datasource_no_type(http_requests, caplog):
datasource = {'value': "https://whatever.com/json"}
assert data_sources.get_items(datasource) == []
assert not data_sources.get_object(datasource)
assert "Data source %s has no known type" % datasource in caplog.records[-1].message
def test_json_datasource_bad_url_scheme(caplog):
datasource = {'type': 'json', 'value': ''}
assert data_sources.get_items(datasource) == []

View File

@ -127,7 +127,7 @@ def get_structured_items(data_source, mode=None):
items.sort(key=lambda x: qommon.misc.simplify(x['text']))
return items
if data_source.get('type') not in ('json', 'jsonp', 'formula'):
if data_source.get('type') and data_source.get('type') not in ('json', 'jsonp', 'formula'):
# named data source
named_data_source = NamedDataSource.get_by_slug(data_source['type'])
if named_data_source.cache_duration:
@ -238,6 +238,9 @@ def get_object(data_source):
if not data_source:
return None
ds_type = data_source.get('type')
if not ds_type:
get_logger().warn('Data source %s has no known type' % data_source)
return None
if ds_type in ('json', 'jsonp', 'formula'):
named_data_source = NamedDataSource()
named_data_source.data_source = data_source