diff options
author | David-Wobrock <david.wobrock@gmail.com> | 2020-10-05 17:39:53 +0200 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-10-14 20:03:07 +0200 |
commit | a0571c1003c5a312a6a2ce7409799d77f2d95025 (patch) | |
tree | d45276eaf9bfc0e575257a9f9d7178707ed9a50d /tests/db_functions | |
parent | b26ec77deb7c5052163ef8514ec7db70c0a5ea2a (diff) | |
download | django-a0571c1003c5a312a6a2ce7409799d77f2d95025.tar.gz |
Refs #31640 -- Made Extract raise ValueError when using tzinfo with Date/TimeField.
Diffstat (limited to 'tests/db_functions')
-rw-r--r-- | tests/db_functions/datetime/test_extract_trunc.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/db_functions/datetime/test_extract_trunc.py b/tests/db_functions/datetime/test_extract_trunc.py index f898ba5253..a842eb9418 100644 --- a/tests/db_functions/datetime/test_extract_trunc.py +++ b/tests/db_functions/datetime/test_extract_trunc.py @@ -1111,6 +1111,18 @@ class DateFunctionWithTimeZoneTests(DateFunctionTests): self.assertEqual(model.day_melb, 16) self.assertEqual(model.day_utc, 15) + def test_extract_invalid_field_with_timezone(self): + melb = pytz.timezone('Australia/Melbourne') + msg = 'tzinfo can only be used with DateTimeField.' + with self.assertRaisesMessage(ValueError, msg): + DTModel.objects.annotate( + day_melb=Extract('start_date', 'day', tzinfo=melb), + ).get() + with self.assertRaisesMessage(ValueError, msg): + DTModel.objects.annotate( + hour_melb=Extract('start_time', 'hour', tzinfo=melb), + ).get() + def test_trunc_timezone_applied_before_truncation(self): start_datetime = datetime(2016, 1, 1, 1, 30, 50, 321) end_datetime = datetime(2016, 6, 15, 14, 10, 50, 123) |