Adds a test for complex operators combinations.

This commit is contained in:
Bertrand Bordage 2017-11-23 18:48:22 +01:00
parent 27bcb3f38f
commit 4a05f4ae23
3 changed files with 35 additions and 2 deletions

View file

@ -482,12 +482,22 @@ class BackendTests(WagtailTestUtils):
self.assertSetEqual({r.title for r in results},
{'JavaScript: The Definitive Guide'})
results = self.backend.search(Term('Javascript') & Term('Definitive'),
models.Book.objects.all())
self.assertSetEqual({r.title for r in results},
{'JavaScript: The Definitive Guide'})
def test_or(self):
results = self.backend.search(Or([Term('Hobbit'), Term('Towers')]),
models.Book.objects.all())
self.assertSetEqual({r.title for r in results},
{'The Hobbit', 'The Two Towers'})
results = self.backend.search(Term('Hobbit') | Term('Towers'),
models.Book.objects.all())
self.assertSetEqual({r.title for r in results},
{'The Hobbit', 'The Two Towers'})
def test_not(self):
all_other_titles = {
'A Clash of Kings',
@ -503,14 +513,27 @@ class BackendTests(WagtailTestUtils):
'Two Scoops of Django 1.11',
}
results = self.backend.search(Not(PlainText('Javascript')),
results = self.backend.search(Not(Term('Javascript')),
models.Book.objects.all())
self.assertSetEqual({r.title for r in results}, all_other_titles)
results = self.backend.search(~PlainText('Javascript'),
results = self.backend.search(~Term('Javascript'),
models.Book.objects.all())
self.assertSetEqual({r.title for r in results}, all_other_titles)
def test_operators_combination(self):
results = self.backend.search(
((Term('Javascript') & ~Term('Definitive'))
| Term('Python') | Term('Rust'))
| Term('Two'),
models.Book.objects.all())
self.assertSetEqual({r.title for r in results},
{'JavaScript: The good parts',
'Learning Python',
'The Two Towers',
'The Rust Programming Language',
'Two Scoops of Django 1.11'})
@override_settings(
WAGTAILSEARCH_BACKENDS={

View file

@ -68,3 +68,8 @@ class TestDBBackend(BackendTests, TestCase):
@unittest.expectedFailure
def test_not(self):
super().test_not()
# Not implemented yet
@unittest.expectedFailure
def test_operators_combination(self):
super().test_operators_combination()

View file

@ -61,6 +61,11 @@ class TestElasticsearch2SearchBackend(BackendTests, ElasticsearchCommonSearchBac
def test_not(self):
super().test_not()
# Not implemented yet
@unittest.expectedFailure
def test_operators_combination(self):
super().test_operators_combination()
class TestElasticsearch2SearchQuery(TestCase):
def assertDictEqual(self, a, b):