From 23de3297bbd74980a2f6da326acc5da63ddef2fe Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Wed, 3 Feb 2021 11:24:46 +0100 Subject: Add a default_sort option to collections --- tests/test_collection.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'tests/test_collection.py') diff --git a/tests/test_collection.py b/tests/test_collection.py index 6a6e5e3..4c95c2b 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -289,9 +289,9 @@ class testComplexCollection(unittest.TestCase): self.collection.settings['name'], "Fully featured lesana collection", ) - self.assertEqual(len(self.collection.settings['fields']), 9) + self.assertEqual(len(self.collection.settings['fields']), 10) self.assertIsNotNone(self.collection.stemmer) - self.assertEqual(len(self.collection.indexed_fields), 7) + self.assertEqual(len(self.collection.indexed_fields), 8) def test_index(self): indexed = self.collection.update_cache() @@ -379,6 +379,18 @@ class testComplexCollection(unittest.TestCase): self.assertEqual(matches[2].data['amount'], 10) self.assertEqual(matches[3].data['amount'], 2) + def test_default_sorted_search(self): + # search in ascending order + self.collection.start_search('Amount') + res = self.collection.get_search_results() + matches = list(res) + self.assertEqual(len(matches), 4) + print([m.data['order'] for m in matches]) + self.assertEqual(matches[0].data['order'], None) + self.assertEqual(matches[1].data['order'], 'alpha') + self.assertEqual(matches[2].data['order'], 'charlie') + self.assertEqual(matches[3].data['order'], 'zucchini') + class testCollectionWithErrors(unittest.TestCase): def setUp(self): -- cgit v1.2.3