kopia lustrzana https://github.com/wagtail/wagtail
Merge pull request #3523 from savoirfairelinux/fix-3513
Fixed #3513 -- Fixed API pagination for empty searchespull/3525/head
commit
6dbe070e27
|
@ -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']
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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:
|
||||
|
|
Ładowanie…
Reference in New Issue