24 |
24 |
global pub, req
|
25 |
25 |
|
26 |
26 |
pub = create_temporary_pub()
|
|
27 |
pub.cfg['debug'] = {'logger': True}
|
|
28 |
pub.write_cfg()
|
|
29 |
pub.set_config()
|
27 |
30 |
|
28 |
31 |
req = HTTPRequest(None, {'SERVER_NAME': 'example.net', 'SCRIPT_NAME': ''})
|
29 |
32 |
pub._set_request(req)
|
... | ... | |
228 |
231 |
assert data_sources.get_items(datasource) == []
|
229 |
232 |
assert data_sources.get_structured_items(datasource) == []
|
230 |
233 |
|
|
234 |
def test_json_datasource_bad_url(http_requests, caplog):
|
|
235 |
datasource = {'type': 'json', 'value': 'http://remote.example.net/404'}
|
|
236 |
assert data_sources.get_items(datasource) == []
|
|
237 |
assert 'Error loading JSON data source' in caplog.records[-1].message
|
|
238 |
assert 'status: 404' in caplog.records[-1].message
|
|
239 |
|
|
240 |
datasource = {'type': 'json', 'value': 'http://remote.example.net/xml'}
|
|
241 |
assert data_sources.get_items(datasource) == []
|
|
242 |
assert 'Error reading JSON data source output' in caplog.records[-1].message
|
|
243 |
assert 'No JSON object could be decoded' in caplog.records[-1].message
|
|
244 |
|
|
245 |
datasource = {'type': 'json', 'value': 'http://remote.example.net/connection-error'}
|
|
246 |
assert data_sources.get_items(datasource) == []
|
|
247 |
assert 'Error loading JSON data source' in caplog.records[-1].message
|
|
248 |
assert 'error' in caplog.records[-1].message
|
|
249 |
|
|
250 |
def test_json_datasource_bad_url_scheme(caplog):
|
|
251 |
datasource = {'type': 'json', 'value': ''}
|
|
252 |
assert data_sources.get_items(datasource) == []
|
|
253 |
assert caplog.records[-1].message == 'Empty URL in JSON data source'
|
|
254 |
|
|
255 |
datasource = {'type': 'json', 'value': 'foo://bar'}
|
|
256 |
assert data_sources.get_items(datasource) == []
|
|
257 |
assert 'Error loading JSON data source' in caplog.records[-1].message
|
|
258 |
assert 'invalid scheme in URL' in caplog.records[-1].message
|
|
259 |
|
|
260 |
datasource = {'type': 'json', 'value': '/bla/blo'}
|
|
261 |
assert data_sources.get_items(datasource) == []
|
|
262 |
assert 'Error loading JSON data source' in caplog.records[-1].message
|
|
263 |
assert 'invalid scheme in URL' in caplog.records[-1].message
|
231 |
264 |
|
232 |
265 |
def test_item_field_named_python_datasource():
|
233 |
266 |
NamedDataSource.wipe()
|