Merge pull request #3523 from savoirfairelinux/fix-3513

Fixed #3513 -- Fixed API pagination for empty searches
pull/3525/head
Bertrand Bordage 2017-04-06 19:47:06 +02:00 zatwierdzone przez GitHub
commit 6dbe070e27
3 zmienionych plików z 30 dodań i 3 usunięć

Wyświetl plik

@ -82,7 +82,6 @@ class TestPageListing(TestCase):
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(content['meta']['total_count'], new_total_count)
# TYPE FILTER
def test_type_filter_items_are_all_blog_entries(self):
@ -739,6 +738,13 @@ class TestPageListing(TestCase):
self.assertEqual(set(page_id_list), set([16, 18, 19]))
def test_empty_searches_work(self):
response = self.get_response(search='')
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-type'], 'application/json')
self.assertEqual(content['meta']['total_count'], 0)
class TestPageDetail(TestCase):
fixtures = ['demosite.json']

Wyświetl plik

@ -534,6 +534,13 @@ class TestPageListing(TestCase):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "filtering by tag with a search query is not supported"})
def test_empty_searches_work(self):
response = self.get_response(search='')
content = json.loads(response.content.decode('UTF-8'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-type'], 'application/json')
self.assertEqual(content['meta']['total_count'], 0)
class TestPageDetail(TestCase):
fixtures = ['demosite.json']

Wyświetl plik

@ -186,6 +186,20 @@ class BaseSearchResults(object):
return clone
class EmptySearchResults(BaseSearchResults):
def __init__(self):
return super(EmptySearchResults, self).__init__(None, None)
def _clone(self):
return self.__class__()
def _do_search(self):
return []
def _do_count(self):
return 0
class BaseSearchBackend(object):
query_class = None
results_class = None
@ -230,11 +244,11 @@ class BaseSearchBackend(object):
# Model must be a class that is in the index
if not class_is_indexed(model):
return []
return EmptySearchResults()
# Check that theres still a query string after the clean up
if query_string == "":
return []
return EmptySearchResults()
# Only fields that are indexed as a SearchField can be passed in fields
if fields: