summaryrefslogtreecommitdiffstats
path: root/tests/test_search.py
diff options
context:
space:
mode:
authorThomas NOEL <tnoel@entrouvert.com>2019-10-24 08:33:30 (GMT)
committerThomas NOEL <tnoel@entrouvert.com>2019-10-24 08:33:30 (GMT)
commit0ac75fcabfe7bddc823f1ccc9eecdaf5a43aaf96 (patch)
tree9b490dd0e5519f94fbd4c1c8dd0d9241a02ac2bf /tests/test_search.py
parent446495b2c2222ab691ea72fbc28982857209fb39 (diff)
downloadcombo-wip/37174-bad-json.zip
combo-wip/37174-bad-json.tar.gz
combo-wip/37174-bad-json.tar.bz2
search: handle bad JSON engine results as empty (#37174)wip/37174-bad-json
Diffstat (limited to 'tests/test_search.py')
-rw-r--r--tests/test_search.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_search.py b/tests/test_search.py
index 2ee67eb..d110596 100644
--- a/tests/test_search.py
+++ b/tests/test_search.py
@@ -113,6 +113,21 @@ def test_search_cell(app):
assert resp.text.count('<li>') == 1
assert '<li><a href="http://test">barbarbar</a>' in resp.text
+ # search engine does not return valid JSON
+ class FakedResponse(mock.Mock):
+ def json(self):
+ return json.loads(self.content)
+ requests_get.return_value = FakedResponse(content='notjson', status_code=200)
+ resp = app.get('/ajax/search/%s/search_alternate_key/?q=bar' % cell.pk, status=200)
+ assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=bar'
+ assert '<li>' not in resp.text
+ assert 'no result found' in resp.text
+ requests_get.return_value = FakedResponse(content='500withbadjson', status_code=500)
+ resp = app.get('/ajax/search/%s/search_alternate_key/?q=foo' % cell.pk, status=200)
+ assert requests_get.call_args[0][0] == 'http://www.example.net/search/?q=foo'
+ assert '<li>' not in resp.text
+ assert 'no result found' in resp.text
+
with override_settings(TEMPLATE_VARS=TEMPLATE_VARS):
cell._search_services = {'data': ['search_tmpl']}
cell.save()