summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml1
-rw-r--r--tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml1
-rw-r--r--tests/data/complex/settings.yaml4
-rw-r--r--tests/test_collection.py9
-rw-r--r--tests/test_types.py29
5 files changed, 41 insertions, 3 deletions
diff --git a/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml b/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml
index bb97781..3132884 100644
--- a/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml
+++ b/tests/data/complex/items/5084bc6e94f24dc6976629282ef30419.yaml
@@ -16,4 +16,5 @@ order: delta
created:
updated:
epoch:
+version: 0
# and a comment at the end
diff --git a/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml b/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml
index 44d8b89..690b680 100644
--- a/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml
+++ b/tests/data/complex/items/8e9fa1ed3c1b4a30a6be7a98eda0cfa7.yaml
@@ -14,3 +14,4 @@ order:
created:
updated:
epoch:
+version: 2
diff --git a/tests/data/complex/settings.yaml b/tests/data/complex/settings.yaml
index bf64934..7aaf47b 100644
--- a/tests/data/complex/settings.yaml
+++ b/tests/data/complex/settings.yaml
@@ -48,3 +48,7 @@ fields:
- name: epoch
type: datetime
auto: false
+ - name: version
+ type: integer
+ auto: increment
+ increment: 2
diff --git a/tests/test_collection.py b/tests/test_collection.py
index 527acf9..84c535d 100644
--- a/tests/test_collection.py
+++ b/tests/test_collection.py
@@ -297,7 +297,7 @@ class testComplexCollection(unittest.TestCase):
self.collection.settings['name'],
"Fully featured lesana collection",
)
- self.assertEqual(len(self.collection.settings['fields']), 13)
+ self.assertEqual(len(self.collection.settings['fields']), 14)
self.assertIsNotNone(self.collection.stemmer)
self.assertEqual(len(self.collection.indexed_fields), 8)
@@ -424,21 +424,24 @@ class testComplexCollection(unittest.TestCase):
eid = '5084bc6e94f24dc6976629282ef30419'
entry = self.collection.entry_from_eid(eid)
# we keep the old data, and check that the updated field is
- # empty
+ # empty and the version field is 0
old_data = entry.data.copy()
self.assertEqual(entry.data['updated'], None)
+ self.assertEqual(entry.data['version'], 0)
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).
+ # to avoid breaking tests too often with race conditions) and
+ # version has grown to 2.
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)
+ self.assertEqual(entry.data['version'], 2)
class testCollectionWithErrors(unittest.TestCase):
diff --git a/tests/test_types.py b/tests/test_types.py
index 260167c..1efcde1 100644
--- a/tests/test_types.py
+++ b/tests/test_types.py
@@ -82,6 +82,35 @@ class testTypes(unittest.TestCase):
v = checker.update(10)
self.assertEqual(v, 10)
+ def test_datetime_auto_increment(self):
+ field_def = self._get_field_def('integer')
+ field_def['auto'] = 'increment'
+ checker = types.LesanaInt(field_def, {})
+
+ v = checker.empty()
+ self.assertEqual(v, 0)
+
+ v = checker.update(0)
+ self.assertEqual(v, 1)
+
+ field_def['increment'] = -1
+ checker = types.LesanaInt(field_def, {})
+ v = checker.update(0)
+ self.assertEqual(v, -1)
+
+ field_def['increment'] = 0.5
+ checker = types.LesanaInt(field_def, {})
+ with self.assertLogs() as cm:
+ v = checker.update(0)
+ self.assertIn('WARNING', cm.output[0])
+ self.assertIn('Invalid configuration value', cm.output[0])
+ self.assertEqual(v, 0)
+
+ field_def['auto'] = 'false'
+ checker = types.LesanaInt(field_def, {})
+ v = checker.update(0)
+ self.assertEqual(v, 0)
+
def test_float(self):
checker = types.LesanaFloat(self._get_field_def('float'), {})