summaryrefslogtreecommitdiffstats
path: root/tests/test_search.py
diff options
context:
space:
mode:
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()