Author: aaugustin
Date: 2011-11-20 07:29:39 -0800 (Sun, 20 Nov 2011)
New Revision: 17126

Modified:
   django/trunk/tests/modeltests/timezones/tests.py
Log:
Ensured that the warning added at r17117 also applies to queryset filter 
arguments. Refs #17263.


Modified: django/trunk/tests/modeltests/timezones/tests.py
===================================================================
--- django/trunk/tests/modeltests/timezones/tests.py    2011-11-20 11:12:37 UTC 
(rev 17125)
+++ django/trunk/tests/modeltests/timezones/tests.py    2011-11-20 15:29:39 UTC 
(rev 17126)
@@ -242,6 +242,7 @@
     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_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_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 @@
         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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to