From 2e3a3ace848d25c8c7cbee4d7da671a10375abbb Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 30 Oct 2020 13:59:54 +0100 Subject: Support sorting search results --- tests/test_collection.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/test_collection.py b/tests/test_collection.py index f3e06da..8d4cf88 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -332,6 +332,27 @@ class testComplexCollection(unittest.TestCase): with open(fname, 'r') as fp: self.assertEqual(e.yaml_data, fp.read()) + def test_sorted_search(self): + # search in ascending order + self.collection.start_search('Amount', sort_by=['amount']) + res = self.collection.get_search_results() + matches = list(res) + self.assertEqual(len(matches), 4) + self.assertEqual(matches[0].data['amount'], 2) + self.assertEqual(matches[1].data['amount'], 10) + self.assertEqual(matches[2].data['amount'], 15) + self.assertEqual(matches[3].data['amount'], 20) + + # and in descending order + self.collection.start_search('Amount', sort_by=['-amount']) + res = self.collection.get_search_results() + matches = list(res) + self.assertEqual(len(matches), 4) + self.assertEqual(matches[0].data['amount'], 20) + self.assertEqual(matches[1].data['amount'], 15) + self.assertEqual(matches[2].data['amount'], 10) + self.assertEqual(matches[3].data['amount'], 2) + class testCollectionWithErrors(unittest.TestCase): def setUp(self): -- cgit v1.2.3