Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensured that the warning added at r17117 also applies to queryset fil…

…ter arguments. Refs #17263.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17126 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 37b7f00fd0c86bcd6f935ae401095864076acd4d 1 parent 5c99013
Aymeric Augustin aaugustin authored
Showing with 19 additions and 0 deletions.
  1. +19 −0 tests/modeltests/timezones/tests.py
19 tests/modeltests/timezones/tests.py
View
@@ -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 @@ def test_naive_datetime(self):
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 @@ def test_naive_datetime_with_microsecond(self):
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 @@ def test_query_filter_with_pytz_timezones(self):
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
Please sign in to comment.
Something went wrong with that request. Please try again.