From 99a1c2f6a5c953f969c4d9e97399a875857d9e20 Mon Sep 17 00:00:00 2001 From: Ross Jones Date: Fri, 19 Feb 2016 12:03:44 +0000 Subject: [PATCH] Add yet another potential error message. Because we support so many 'versions' of Solr, we're encountering different error messages as the only way of determining what went wrong. In some cases the response is HTML :( To fix this we explicitly check in the test if it succeeded (we get a 200 when we get an error response) and inform the dev where to go to add their newly discovered error message. --- ckan/lib/search/query.py | 2 ++ ckan/tests/controllers/test_package.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ckan/lib/search/query.py b/ckan/lib/search/query.py index 71bad2d3f90..2f7215cad12 100644 --- a/ckan/lib/search/query.py +++ b/ckan/lib/search/query.py @@ -362,7 +362,9 @@ def run(self, query): # Error with the sort parameter. You see slightly different # error messages depending on whether the SOLR JSON comes back # or Jetty gets in the way converting it to HTML - not sure why + # if "Can't determine a Sort Order" in e.body or \ + "Can't determine Sort Order" in e.body or \ 'Unknown sort order' in e.body: raise SearchQueryError('Invalid "sort" parameter') raise SearchError( diff --git a/ckan/tests/controllers/test_package.py b/ckan/tests/controllers/test_package.py index 117726a3784..fe7caf96415 100644 --- a/ckan/tests/controllers/test_package.py +++ b/ckan/tests/controllers/test_package.py @@ -758,7 +758,13 @@ def test_search_sort_by_bad(self): offset = url_for(controller='package', action='search') + \ '?sort=gvgyr_fgevat+nfp' app = self._get_test_app() - app.get(offset, status=400) + response = app.get(offset, status=[200, 400]) + if response.status == 200: + import sys + sys.stdout.write(response.body) + raise Exception("Solr returned an unknown error message. " + "Please check the error handling " + "in ckan/lib/search/query.py:run") def test_search_solr_syntax_error(self): factories.Dataset()