From a4433548c49da3140f3cda42d300803c583e7e36 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Mon, 8 Feb 2021 16:39:39 +0100 Subject: Add the option to autofill date and datetime fields at creation time. --- tests/test_types.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests/test_types.py') 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'), {}) -- cgit v1.2.3