From f556ea9ad72af80c17a456bcc8248e57f2afe0e5 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Thu, 25 Mar 2021 09:51:23 +0100 Subject: Start getting the list and frequency of values for a field. --- tests/data/complex/settings.yaml | 1 + tests/test_collection.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/data/complex/settings.yaml b/tests/data/complex/settings.yaml index 7aaf47b..671a9b0 100644 --- a/tests/data/complex/settings.yaml +++ b/tests/data/complex/settings.yaml @@ -15,6 +15,7 @@ fields: - name: position type: string index: field + sortable: true - name: something type: yaml - name: tags diff --git a/tests/test_collection.py b/tests/test_collection.py index 2af4cfe..d05415f 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -285,6 +285,15 @@ class testSimpleCollection(unittest.TestCase): with open(fname, 'r') as fp: self.assertEqual(entry.yaml_data, fp.read()) + def test_list_values(self): + values = self.collection.get_field_values('position') + values = list(values) + self.assertEqual(len(values), 2) + self.assertEqual(values, [ + {'value': 'somewhere', 'frequency': 2}, + {'value': None, 'frequency': 1}, + ]) + class testComplexCollection(unittest.TestCase): def setUp(self): @@ -455,6 +464,16 @@ class testComplexCollection(unittest.TestCase): self.assertEqual(entry.data['updated'].year, now.year) self.assertEqual(entry.data['version'], 2) + def test_list_values(self): + values = self.collection.get_field_values('position') + values = list(values) + self.assertEqual(values, [ + {'value': b'Somewhere', 'frequency': 1}, + {'value': b'over there', 'frequency': 1}, + {'value': b'somewhere', 'frequency': 1}, + {'value': b'there', 'frequency': 1}, + ]) + class testCollectionWithErrors(unittest.TestCase): def setUp(self): -- cgit v1.2.3