From 4a05f4ae23e6e4ac91a4b0628d8646fad96b5344 Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Thu, 23 Nov 2017 18:48:22 +0100 Subject: [PATCH] Adds a test for complex operators combinations. --- wagtail/wagtailsearch/tests/test_backends.py | 27 +++++++++++++++++-- .../wagtailsearch/tests/test_db_backend.py | 5 ++++ .../tests/test_elasticsearch2_backend.py | 5 ++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/wagtail/wagtailsearch/tests/test_backends.py b/wagtail/wagtailsearch/tests/test_backends.py index d3295b1f7..46a0a7dce 100644 --- a/wagtail/wagtailsearch/tests/test_backends.py +++ b/wagtail/wagtailsearch/tests/test_backends.py @@ -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={ diff --git a/wagtail/wagtailsearch/tests/test_db_backend.py b/wagtail/wagtailsearch/tests/test_db_backend.py index 47ce49f5f..3db2bd16c 100644 --- a/wagtail/wagtailsearch/tests/test_db_backend.py +++ b/wagtail/wagtailsearch/tests/test_db_backend.py @@ -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() diff --git a/wagtail/wagtailsearch/tests/test_elasticsearch2_backend.py b/wagtail/wagtailsearch/tests/test_elasticsearch2_backend.py index e9759b6db..936a50e4b 100644 --- a/wagtail/wagtailsearch/tests/test_elasticsearch2_backend.py +++ b/wagtail/wagtailsearch/tests/test_elasticsearch2_backend.py @@ -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):