0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00

Fixes a test to account for a normal random ordering.

This commit is contained in:
Bertrand Bordage 2017-08-23 18:31:26 +02:00
parent 8d08f83c5a
commit 67bc54f628

View File

@ -181,25 +181,24 @@ class BackendTests(WagtailTestUtils):
self.assertEqual(set(results), {self.testa}) self.assertEqual(set(results), {self.testa})
def test_boost(self): 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” # The `content` field has more boost, so the object containing “Hello”
# should be before the ones having it in the title, # should be before the ones having it in the title,
# despite the insertion order. # despite the insertion order.
self.assertListEqual( self.assertEqual(results[0], self.testc.searchtest_ptr)
list(results), [self.testc.searchtest_ptr, self.testa, self.testb]) self.assertSetEqual(set(results[1:]), {self.testa, self.testb})
def test_order_by_relevance(self): def test_order_by_relevance(self):
sorted_results = self.backend.search('Hello', models.SearchTest, sorted_results = list(self.backend.search('Hello', models.SearchTest,
order_by_relevance=True) order_by_relevance=True))
self.assertListEqual( self.assertEqual(sorted_results[0], self.testc.searchtest_ptr)
list(sorted_results), self.assertSetEqual(set(sorted_results[1:]), {self.testa, self.testb})
[self.testc.searchtest_ptr, self.testa, self.testb])
unsorted_results = self.backend.search('Hello', models.SearchTest, unsorted_results = list(self.backend.search('Hello', models.SearchTest,
order_by_relevance=False) order_by_relevance=False))
self.assertListEqual( self.assertSetEqual(
list(unsorted_results), set(unsorted_results),
[self.testa, self.testb, self.testc.searchtest_ptr]) {self.testa, self.testb, self.testc.searchtest_ptr})
def test_delete(self): def test_delete(self):
# Delete one of the objects # Delete one of the objects