From ec186572e6cfde4cd4bc1491ff552c5d32211d9f Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 12 Apr 2015 14:46:24 +0200 Subject: Removed global timezone-aware datetime converters. Refs #23820. --- tests/timezones/tests.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py index 8c1d533165..39158badc1 100644 --- a/tests/timezones/tests.py +++ b/tests/timezones/tests.py @@ -10,6 +10,7 @@ from xml.dom.minidom import parseString from django.contrib.auth.models import User from django.core import serializers from django.core.urlresolvers import reverse +from django.db import connection from django.db.models import Max, Min from django.http import HttpRequest from django.template import ( @@ -265,6 +266,13 @@ class LegacyDatabaseTests(TestCase): [event], transform=lambda d: d) + def test_cursor_execute_returns_naive_datetime(self): + dt = datetime.datetime(2011, 9, 1, 13, 20, 30) + Event.objects.create(dt=dt) + with connection.cursor() as cursor: + cursor.execute('SELECT dt FROM timezones_event WHERE dt = %s', [dt]) + self.assertEqual(cursor.fetchall()[0][0], dt) + def test_filter_date_field_with_aware_datetime(self): # Regression test for #17742 day = datetime.date(2011, 9, 1) @@ -556,6 +564,23 @@ class NewDatabaseTests(TestCase): [event], transform=lambda d: d) + @skipUnlessDBFeature('supports_timezones') + def test_cursor_execute_returns_aware_datetime(self): + dt = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT) + Event.objects.create(dt=dt) + with connection.cursor() as cursor: + cursor.execute('SELECT dt FROM timezones_event WHERE dt = %s', [dt]) + self.assertEqual(cursor.fetchall()[0][0], dt) + + @skipIfDBFeature('supports_timezones') + def test_cursor_execute_returns_naive_datetime(self): + dt = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT) + utc_naive_dt = timezone.make_naive(dt, timezone.utc) + Event.objects.create(dt=dt) + with connection.cursor() as cursor: + cursor.execute('SELECT dt FROM timezones_event WHERE dt = %s', [dt]) + self.assertEqual(cursor.fetchall()[0][0], utc_naive_dt) + @requires_tz_support def test_filter_date_field_with_aware_datetime(self): # Regression test for #17742 -- cgit v1.3