From 37b7f00fd0c86bcd6f935ae401095864076acd4d Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 20 Nov 2011 15:29:39 +0000 Subject: [PATCH] Ensured that the warning added at r17117 also applies to queryset filter arguments. Refs #17263. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17126 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/timezones/tests.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/modeltests/timezones/tests.py b/tests/modeltests/timezones/tests.py index b7ae764b0a..a2f4ad2029 100644 --- a/tests/modeltests/timezones/tests.py +++ b/tests/modeltests/timezones/tests.py @@ -242,6 +242,7 @@ class NewDatabaseTests(BaseDateTimeTests): def test_naive_datetime(self): dt = datetime.datetime(2011, 9, 1, 13, 20, 30) with warnings.catch_warnings(record=True) as recorded: + warnings.simplefilter('always') Event.objects.create(dt=dt) self.assertEqual(len(recorded), 1) msg = str(recorded[0].message) @@ -255,6 +256,7 @@ class NewDatabaseTests(BaseDateTimeTests): def test_naive_datetime_with_microsecond(self): dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060) with warnings.catch_warnings(record=True) as recorded: + warnings.simplefilter('always') Event.objects.create(dt=dt) self.assertEqual(len(recorded), 1) msg = str(recorded[0].message) @@ -268,6 +270,7 @@ class NewDatabaseTests(BaseDateTimeTests): def test_naive_datetime_with_microsecond_unsupported(self): dt = datetime.datetime(2011, 9, 1, 13, 20, 30, 405060) with warnings.catch_warnings(record=True) as recorded: + warnings.simplefilter('always') Event.objects.create(dt=dt) self.assertEqual(len(recorded), 1) msg = str(recorded[0].message) @@ -344,6 +347,22 @@ class NewDatabaseTests(BaseDateTimeTests): self.assertEqual(Event.objects.filter(dt__in=(prev, dt, next)).count(), 1) self.assertEqual(Event.objects.filter(dt__range=(prev, next)).count(), 1) + @skipIf(sys.version_info < (2, 6), "this test requires Python >= 2.6") + def test_query_filter_with_naive_datetime(self): + dt = datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT) + Event.objects.create(dt=dt) + dt = dt.replace(tzinfo=None) + with warnings.catch_warnings(record=True) as recorded: + warnings.simplefilter('always') + # naive datetimes are interpreted in local time + self.assertEqual(Event.objects.filter(dt__exact=dt).count(), 1) + self.assertEqual(Event.objects.filter(dt__lte=dt).count(), 1) + self.assertEqual(Event.objects.filter(dt__gt=dt).count(), 0) + self.assertEqual(len(recorded), 3) + for warning in recorded: + msg = str(warning.message) + self.assertTrue(msg.startswith("DateTimeField received a naive datetime")) + def test_query_date_related_filters(self): # These two dates fall in the same day in EAT, but in different days, # years and months in UTC, and aggregation is performed in UTC when