From f479df7f8d03ab767bb5e5d655243191087d6432 Mon Sep 17 00:00:00 2001 From: Daniyal Date: Wed, 24 Mar 2021 11:15:08 +0530 Subject: Refs #32508 -- Raised Type/ValueError instead of using "assert" in django.db.models. Co-authored-by: Mariusz Felisiak --- tests/datetimes/tests.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/datetimes') diff --git a/tests/datetimes/tests.py b/tests/datetimes/tests.py index f42936b557..7f98032e0a 100644 --- a/tests/datetimes/tests.py +++ b/tests/datetimes/tests.py @@ -199,3 +199,16 @@ class DateTimesTests(TestCase): Article.objects.create(pub_date=dt, published_on=dt.date(), title="Don't put dates into datetime functions!") with self.assertRaisesMessage(ValueError, "Cannot truncate DateField 'published_on' to DateTimeField"): list(Article.objects.datetimes('published_on', 'second')) + + def test_datetimes_fails_when_given_invalid_kind_argument(self): + msg = ( + "'kind' must be one of 'year', 'month', 'week', 'day', 'hour', " + "'minute', or 'second'." + ) + with self.assertRaisesMessage(ValueError, msg): + Article.objects.datetimes('pub_date', 'bad_kind') + + def test_datetimes_fails_when_given_invalid_order_argument(self): + msg = "'order' must be either 'ASC' or 'DESC'." + with self.assertRaisesMessage(ValueError, msg): + Article.objects.datetimes('pub_date', 'year', order='bad order') -- cgit v1.3