diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml | 1 | ||||
| -rw-r--r-- | tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml | 1 | ||||
| -rw-r--r-- | tests/data/complex/settings.yaml | 3 | ||||
| -rw-r--r-- | tests/test_collection.py | 30 | 
4 files changed, 34 insertions, 1 deletions
| diff --git a/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml b/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml index d4cdaba..bb97781 100644 --- a/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml +++ b/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml @@ -14,5 +14,6 @@ with_default: default value  amount: 1  order: delta  created: +updated:  epoch:  # and a comment at the end diff --git a/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml b/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml index ab9dc70..44d8b89 100644 --- a/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml +++ b/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml @@ -12,4 +12,5 @@ with_default: 'default value'  amount: 0  order:  created: +updated:  epoch: diff --git a/tests/data/complex/settings.yaml b/tests/data/complex/settings.yaml index 1c48b52..bf64934 100644 --- a/tests/data/complex/settings.yaml +++ b/tests/data/complex/settings.yaml @@ -42,6 +42,9 @@ fields:      - name: created        type: datetime        auto: creation +    - name: updated +      type: datetime +      auto: update      - name: epoch        type: datetime        auto: false diff --git a/tests/test_collection.py b/tests/test_collection.py index 4fa292e..527acf9 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -1,3 +1,4 @@ +import datetime  import logging  import os.path  import shutil @@ -117,6 +118,13 @@ class testEntries(unittest.TestCase):          self.assertIn("name: ''", entry.yaml_data)          self.assertIn('quantity: 0', entry.yaml_data) +    def test_update_entry(self): +        eid = '11189ee47ddf4796b718a483b379f976' +        entry = self.collection.entry_from_eid(eid) +        old_data = entry.data.copy() +        entry.update() +        self.assertEqual(old_data, entry.data) +  class testEmptyCollection(unittest.TestCase):      def setUp(self): @@ -289,7 +297,7 @@ class testComplexCollection(unittest.TestCase):              self.collection.settings['name'],              "Fully featured lesana collection",          ) -        self.assertEqual(len(self.collection.settings['fields']), 12) +        self.assertEqual(len(self.collection.settings['fields']), 13)          self.assertIsNotNone(self.collection.stemmer)          self.assertEqual(len(self.collection.indexed_fields), 8) @@ -412,6 +420,26 @@ class testComplexCollection(unittest.TestCase):          self.assertEqual(matches[7].data['order'], 'delta')          self.assertEqual(matches[8].data['order'], 'zucchini') +    def test_update_entry(self): +        eid = '5084bc6e94f24dc6976629282ef30419' +        entry = self.collection.entry_from_eid(eid) +        # we keep the old data, and check that the updated field is +        # empty +        old_data = entry.data.copy() +        self.assertEqual(entry.data['updated'], None) + +        entry.update() + +        # after the update, fields that were not supposed to be updated +        # are equal to what they were before, while updated has been +        # changed to a datetime in this year (we don't check too deeply +        # to avoid breaking tests too often with race conditions). +        for field in ('created', 'epoch'): +            self.assertEqual(old_data[field], entry.data[field]) +        now = datetime.datetime.now(datetime.timezone.utc) +        self.assertIsInstance(entry.data['updated'], datetime.datetime) +        self.assertEqual(entry.data['updated'].year, now.year) +  class testCollectionWithErrors(unittest.TestCase):      def setUp(self): | 
