summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-02-03 11:24:46 +0100
committerElena ``of Valhalla'' Grandi <valhalla@trueelena.org>2021-02-03 11:24:46 +0100
commit23de3297bbd74980a2f6da326acc5da63ddef2fe (patch)
treefc670e596e96a2147ee0f27a838072ba98645e25 /tests
parentde1c03d81615e6fd50540008fe6ca46feb012c30 (diff)
Add a default_sort option to collections
Diffstat (limited to 'tests')
-rw-r--r--tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml1
-rw-r--r--tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml1
-rw-r--r--tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml1
-rw-r--r--tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml1
-rw-r--r--tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml1
-rw-r--r--tests/data/complex/settings.yaml6
-rw-r--r--tests/test_collection.py16
7 files changed, 25 insertions, 2 deletions
diff --git a/tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml b/tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml
index c9aece7..6fd18e1 100644
--- a/tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml
+++ b/tests/data/complex/items/0b33e2b72add4ccab93a8cb7e2014b10.yaml
@@ -8,3 +8,4 @@ keywords: []
exists:
with_default: default value
amount: 2
+order: charlie
diff --git a/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml b/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml
index 874833e..6abdd6d 100644
--- a/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml
+++ b/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml
@@ -12,4 +12,5 @@ keywords: []
exists: true
with_default: default value
amount: 1
+order: delta
# and a comment at the end
diff --git a/tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml b/tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml
index c57b5f0..18ff2c9 100644
--- a/tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml
+++ b/tests/data/complex/items/5be0a92b6ad745fc9ffced106c94d221.yaml
@@ -8,3 +8,4 @@ keywords: []
exists:
with_default: default value
amount: 10
+order: alpha
diff --git a/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml b/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml
index e23a563..da82d8d 100644
--- a/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml
+++ b/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml
@@ -10,3 +10,4 @@ keywords: []
exists:
with_default: 'default value'
amount: 0
+order:
diff --git a/tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml b/tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml
index 50c57e2..6661167 100644
--- a/tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml
+++ b/tests/data/complex/items/b4b1feb620aa46f5b6784fbc608e4cd8.yaml
@@ -8,3 +8,4 @@ keywords: []
exists:
with_default: default value
amount: 20
+order: zucchini
diff --git a/tests/data/complex/settings.yaml b/tests/data/complex/settings.yaml
index e6781b5..1fd36b5 100644
--- a/tests/data/complex/settings.yaml
+++ b/tests/data/complex/settings.yaml
@@ -1,6 +1,8 @@
name: "Fully featured lesana collection"
lang: 'english'
entry_label: '{{ eid }}: {{ name }} ({{ tags }})'
+default_sort:
+ - order
fields:
- name: name
type: string
@@ -33,3 +35,7 @@ fields:
type: integer
index: field
sortable: true
+ - name: order
+ type: string
+ index: field
+ sortable: true
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):