summaryrefslogtreecommitdiff
path: root/tests/db_functions
diff options
context:
space:
mode:
authorHasan Ramezani <hasan.r67@gmail.com>2019-07-11 21:13:36 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-07-12 08:08:35 +0200
commit402e6d292fd8aa5dfd49166e80098122950053f7 (patch)
tree6de4e2ba2470bde994f9d025d0d9ed2190cfbb9b /tests/db_functions
parent7a42cfcfdc94c1e7cd653f3140b9eb30492bae4f (diff)
downloaddjango-402e6d292fd8aa5dfd49166e80098122950053f7.tar.gz
Fixed #30602 -- Made Extract raise ValueError when using unsupported lookups for DurationField.
Diffstat (limited to 'tests/db_functions')
-rw-r--r--tests/db_functions/datetime/test_extract_trunc.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/db_functions/datetime/test_extract_trunc.py b/tests/db_functions/datetime/test_extract_trunc.py
index 2b7ee5befd..f2f75ee620 100644
--- a/tests/db_functions/datetime/test_extract_trunc.py
+++ b/tests/db_functions/datetime/test_extract_trunc.py
@@ -273,6 +273,13 @@ class DateFunctionTests(TestCase):
with self.assertRaisesMessage(ValueError, msg):
list(DTModel.objects.annotate(extracted=Extract('duration', 'second')))
+ def test_extract_duration_unsupported_lookups(self):
+ msg = "Cannot extract component '%s' from DurationField 'duration'."
+ for lookup in ('year', 'iso_year', 'month', 'week', 'week_day', 'quarter'):
+ with self.subTest(lookup):
+ with self.assertRaisesMessage(ValueError, msg % lookup):
+ DTModel.objects.annotate(extracted=Extract('duration', lookup))
+
def test_extract_year_func(self):
start_datetime = datetime(2015, 6, 15, 14, 30, 50, 321)
end_datetime = datetime(2016, 6, 15, 14, 10, 50, 123)