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/test_types.py | |
parent | 4b87d38ed0300ba207faf3890123d26fa4af2609 (diff) |
Add the option to autofill date and datetime fields at creation time.
Diffstat (limited to 'tests/test_types.py')
-rw-r--r-- | tests/test_types.py | 33 |
1 files changed, 33 insertions, 0 deletions
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'), {}) |