From 67bc54f6285d3cdebc238ecb4a5fbd4d543c7725 Mon Sep 17 00:00:00 2001 From: Bertrand Bordage Date: Wed, 23 Aug 2017 18:31:26 +0200 Subject: [PATCH] Fixes a test to account for a normal random ordering. --- wagtail/wagtailsearch/tests/test_backends.py | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/wagtail/wagtailsearch/tests/test_backends.py b/wagtail/wagtailsearch/tests/test_backends.py index e6c5d2bf6c..95a71d0527 100644 --- a/wagtail/wagtailsearch/tests/test_backends.py +++ b/wagtail/wagtailsearch/tests/test_backends.py @@ -181,25 +181,24 @@ class BackendTests(WagtailTestUtils): self.assertEqual(set(results), {self.testa}) def test_boost(self): - results = self.backend.search('Hello', models.SearchTest) + results = list(self.backend.search('Hello', models.SearchTest)) # The `content` field has more boost, so the object containing “Hello” # should be before the ones having it in the title, # despite the insertion order. - self.assertListEqual( - list(results), [self.testc.searchtest_ptr, self.testa, self.testb]) + self.assertEqual(results[0], self.testc.searchtest_ptr) + self.assertSetEqual(set(results[1:]), {self.testa, self.testb}) def test_order_by_relevance(self): - sorted_results = self.backend.search('Hello', models.SearchTest, - order_by_relevance=True) - self.assertListEqual( - list(sorted_results), - [self.testc.searchtest_ptr, self.testa, self.testb]) + sorted_results = list(self.backend.search('Hello', models.SearchTest, + order_by_relevance=True)) + self.assertEqual(sorted_results[0], self.testc.searchtest_ptr) + self.assertSetEqual(set(sorted_results[1:]), {self.testa, self.testb}) - unsorted_results = self.backend.search('Hello', models.SearchTest, - order_by_relevance=False) - self.assertListEqual( - list(unsorted_results), - [self.testa, self.testb, self.testc.searchtest_ptr]) + unsorted_results = list(self.backend.search('Hello', models.SearchTest, + order_by_relevance=False)) + self.assertSetEqual( + set(unsorted_results), + {self.testa, self.testb, self.testc.searchtest_ptr}) def test_delete(self): # Delete one of the objects