diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2021-02-08 16:39:39 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2021-02-08 16:39:39 +0100 |
commit | a4433548c49da3140f3cda42d300803c583e7e36 (patch) | |
tree | e05b82e688e7e58dcc62ec483320fad48856cfac /tests | |
parent | 4b87d38ed0300ba207faf3890123d26fa4af2609 (diff) |
Add the option to autofill date and datetime fields at creation time.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/data/complex/settings.yaml | 2 | ||||
-rw-r--r-- | tests/test_collection.py | 7 | ||||
-rw-r--r-- | tests/test_types.py | 33 |
3 files changed, 41 insertions, 1 deletions
diff --git a/tests/data/complex/settings.yaml b/tests/data/complex/settings.yaml index 0bdcabb..1c48b52 100644 --- a/tests/data/complex/settings.yaml +++ b/tests/data/complex/settings.yaml @@ -41,5 +41,7 @@ fields: sortable: true - name: created type: datetime + auto: creation - name: epoch type: datetime + auto: false diff --git a/tests/test_collection.py b/tests/test_collection.py index 9f83655..4fa292e 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -319,7 +319,12 @@ class testComplexCollection(unittest.TestCase): self.assertIn('amount: 0', entry.yaml_data) self.assertIn("tags: []", entry.yaml_data) self.assertIn("exists:\n", entry.yaml_data) - self.assertIn("created:\n", entry.yaml_data) + # we just check that created starts with a date and ends with + # the utc timezone to keep the regex short and manageable + self.assertRegex( + entry.yaml_data, + r"created: [\d]{4,4}-[\d]{2,2}-[\d]{2,2} .*\+00\:00" + ) self.assertIn("epoch:\n", entry.yaml_data) def test_load_field_loaders(self): diff --git a/tests/test_types.py b/tests/test_types.py index 6f0c33e..9663288 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -176,6 +176,23 @@ class testTypes(unittest.TestCase): v = checker.load(None) self.assertEqual(v, None) + def test_datetime_auto(self): + field_def = self._get_field_def('datetime') + field_def['auto'] = 'creation' + checker = types.LesanaDatetime(field_def, {}) + + now = datetime.datetime.now() + v = checker.empty() + self.assertIsInstance(v, datetime.datetime) + self.assertEqual(v.tzinfo, datetime.timezone.utc) + self.assertEqual(v.year, now.year) + + field_def['auto'] = False + checker = types.LesanaDatetime(field_def, {}) + + v = checker.empty() + self.assertEqual(v, None) + def test_date(self): checker = types.LesanaDate(self._get_field_def('date'), {}) @@ -205,6 +222,22 @@ class testTypes(unittest.TestCase): v = checker.load(None) self.assertEqual(v, None) + def test_date_auto(self): + field_def = self._get_field_def('date') + field_def['auto'] = 'creation' + checker = types.LesanaDate(field_def, {}) + + today = datetime.date.today() + v = checker.empty() + self.assertIsInstance(v, datetime.date) + self.assertEqual(v, today) + + field_def['auto'] = False + checker = types.LesanaDate(field_def, {}) + + v = checker.empty() + self.assertEqual(v, None) + def test_boolean(self): checker = types.LesanaBoolean(self._get_field_def('boolean'), {}) |