search: do not try to parse results in case of error (#76022) #80

Merged
vdeniaud merged 1 commits from wip/76022-search-ajax-results-view-verifie into main 2023-04-17 13:40:35 +02:00
2 changed files with 10 additions and 0 deletions

View File

@ -284,6 +284,9 @@ class SearchCell(CellBase):
except ValueError:
return render_response(service)
if results.get('err'):
return render_response(service)
if service.get('data_key'):
results['data'] = results.get(service['data_key']) or []
hit_templates = {}

View File

@ -317,6 +317,13 @@ def test_search_custom_templates(app):
assert '<li><a href="http://example.net/123/">A B</a>' in resp.text
assert '<div>description A</div>' in resp.text
# err != 0 is handled
response = {'err': 1, 'data': 'something'}
mock_json.json.return_value = response
resp = app.get('/ajax/search/%s/search2/?q=foo' % cell.pk, status=200)
assert 'no result found' in resp.text
def test_search_cell_visibility(settings, app):
request = RequestFactory().get('/')