Use MATCH_ALL in Elasticsearch tests.

This commit is contained in:
Bertrand Bordage 2017-11-23 16:18:31 +01:00
parent 2ba532d745
commit 70393cb131
3 changed files with 12 additions and 9 deletions

View file

@ -6,6 +6,7 @@ from io import StringIO
from django.core import management
from wagtail.tests.search import models
from wagtail.wagtailsearch.query import MATCH_ALL
class ElasticsearchCommonSearchBackendTests(object):
@ -111,7 +112,7 @@ class ElasticsearchCommonSearchBackendTests(object):
)
# This should not give any results
results = self.backend.search(None, models.Book)
results = self.backend.search(MATCH_ALL, models.Book)
self.assertSetEqual(set(results), set())
def test_annotate_score(self):
@ -129,7 +130,7 @@ class ElasticsearchCommonSearchBackendTests(object):
def test_more_than_ten_results(self):
# #3431 reported that Elasticsearch only sends back 10 results if the results set is not sliced
results = self.backend.search(None, models.Book)
results = self.backend.search(MATCH_ALL, models.Book)
self.assertEqual(len(results), 13)
@ -143,7 +144,7 @@ class ElasticsearchCommonSearchBackendTests(object):
index.add_items(models.Book, books)
index.refresh()
results = self.backend.search(None, models.Book)
results = self.backend.search(MATCH_ALL, models.Book)
self.assertEqual(len(results), 163)
def test_slice_more_than_one_hundred_results(self):
@ -155,7 +156,7 @@ class ElasticsearchCommonSearchBackendTests(object):
index.add_items(models.Book, books)
index.refresh()
results = self.backend.search(None, models.Book)[10:120]
results = self.backend.search(MATCH_ALL, models.Book)[10:120]
self.assertEqual(len(results), 110)
def test_slice_to_next_page(self):
@ -169,5 +170,5 @@ class ElasticsearchCommonSearchBackendTests(object):
index.add_items(models.Book, books)
index.refresh()
results = self.backend.search(None, models.Book)[110:]
results = self.backend.search(MATCH_ALL, models.Book)[110:]
self.assertEqual(len(results), 53)

View file

@ -13,6 +13,7 @@ from elasticsearch.serializer import JSONSerializer
from wagtail.tests.search import models
from wagtail.wagtailsearch.backends.elasticsearch2 import (
Elasticsearch2SearchBackend, get_model_root)
from wagtail.wagtailsearch.query import MATCH_ALL
from .elasticsearch_common_tests import ElasticsearchCommonSearchBackendTests
from .test_backends import BackendTests
@ -57,9 +58,9 @@ class TestElasticsearch2SearchQuery(TestCase):
}}
self.assertDictEqual(query.get_query(), expected_result)
def test_none_query_string(self):
def test_match_all(self):
# Create a query
query = self.query_class(models.Book.objects.all(), None)
query = self.query_class(models.Book.objects.all(), MATCH_ALL)
# Check it
expected_result = {'filtered': {

View file

@ -12,6 +12,7 @@ from elasticsearch.serializer import JSONSerializer
from wagtail.tests.search import models
from wagtail.wagtailsearch.backends.elasticsearch5 import Elasticsearch5SearchBackend
from wagtail.wagtailsearch.query import MATCH_ALL
from .elasticsearch_common_tests import ElasticsearchCommonSearchBackendTests
from .test_backends import BackendTests
@ -61,9 +62,9 @@ class TestElasticsearch5SearchQuery(TestCase):
}}
self.assertDictEqual(query.get_query(), expected_result)
def test_none_query_string(self):
def test_match_all(self):
# Create a query
query = self.query_class(models.Book.objects.all(), None)
query = self.query_class(models.Book.objects.all(), MATCH_ALL)
# Check it
expected_result = {'bool': {