aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-10-30 13:59:54 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2020-10-30 13:59:54 +0100
commit2e3a3ace848d25c8c7cbee4d7da671a10375abbb (patch)
tree3dee6f84d64cc7a74dc9f8a96f52a07f41bba7bf /tests
parent9787d25977f5679b2636fb7d8cb2608cff7ad526 (diff)
Support sorting search results
Diffstat (limited to 'tests')
-rw-r--r--tests/test_collection.py21
1 files changed, 21 insertions, 0 deletions
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):