From ba68390361631becba819bd076259a43d21c32d5 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Tue, 27 Dec 2016 09:28:32 +0100 Subject: Don't die when a settings entry has no 'index' field. --- lesana/collection.py | 2 +- tests/data/wrong/settings.yaml | 1 - tests/test_collection.py | 12 ++++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lesana/collection.py b/lesana/collection.py index d5c42e8..b3a56ff 100644 --- a/lesana/collection.py +++ b/lesana/collection.py @@ -112,7 +112,7 @@ class Collection(object): def indexed_fields(self): fields = [] for field in self.settings['fields']: - if field['index'] in ['free', 'field']: + if field.get('index', '') in ['free', 'field']: prefix = field.get('prefix', 'X'+field['name'].upper()) fields.append({ 'prefix': prefix, diff --git a/tests/data/wrong/settings.yaml b/tests/data/wrong/settings.yaml index 56031e4..9871421 100644 --- a/tests/data/wrong/settings.yaml +++ b/tests/data/wrong/settings.yaml @@ -6,7 +6,6 @@ fields: index: free - name: description type: text - index: free - name: position type: string index: facet diff --git a/tests/test_collection.py b/tests/test_collection.py index 9522ab8..7d2dc72 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -43,6 +43,18 @@ class testCollectionLoading(unittest.TestCase): self.assertIsNotNone(self.collection.settings) self.assertIsNotNone(self.collection.stemmer) + def test_no_index_for_one_entry(self): + # This loads a collection where some of the entries have no + # "index" field + with self.assertLogs(level=logging.WARNING) as cm: + self.collection = lesana.Collection('tests/data/wrong') + self.collection.update_cache() + self.assertIsNotNone(self.collection.settings) + self.assertIsNotNone(self.collection.stemmer) + # Fields with no "index" entry are not indexed + self.assertEqual(len(self.collection.settings['fields']), 3) + self.assertEqual(len(self.collection.indexed_fields), 1) + def test_unsafe(self): self.collection = lesana.Collection('tests/data/simple') self.collection.safe = False -- cgit v1.2.3