diff --git a/tests/modeltests/timezones/tests.py b/tests/modeltests/timezones/tests.py index a38e4b3f75..4621f0a60c 100644 --- a/tests/modeltests/timezones/tests.py +++ b/tests/modeltests/timezones/tests.py @@ -467,6 +467,7 @@ class NewDatabaseTests(TestCase): [event], transform=lambda d: d) + @requires_tz_support def test_filter_date_field_with_aware_datetime(self): # Regression test for #17742 day = datetime.date(2011, 9, 1) diff --git a/tests/regressiontests/generic_views/dates.py b/tests/regressiontests/generic_views/dates.py index 808582a6a5..d18d10e603 100644 --- a/tests/regressiontests/generic_views/dates.py +++ b/tests/regressiontests/generic_views/dates.py @@ -1,14 +1,27 @@ from __future__ import absolute_import +import time import datetime from django.core.exceptions import ImproperlyConfigured from django.test import TestCase from django.test.utils import override_settings from django.utils import timezone +from django.utils.unittest import skipUnless from .models import Book, BookSigning +TZ_SUPPORT = hasattr(time, 'tzset') + +# On OSes that don't provide tzset (Windows), we can't set the timezone +# in which the program runs. As a consequence, we must skip tests that +# don't enforce a specific timezone (with timezone.override or equivalent), +# or attempt to interpret naive datetimes in the default timezone. + +requires_tz_support = skipUnless(TZ_SUPPORT, + "This test relies on the ability to run a program in an arbitrary " + "time zone, but your operating system isn't able to do that.") + class ArchiveIndexViewTests(TestCase): fixtures = ['generic-views-test-data.json'] @@ -100,6 +113,7 @@ class ArchiveIndexViewTests(TestCase): res = self.client.get('/dates/booksignings/') self.assertEqual(res.status_code, 200) + @requires_tz_support @override_settings(USE_TZ=True, TIME_ZONE='Africa/Nairobi') def test_aware_datetime_archive_view(self): BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc)) @@ -502,6 +516,7 @@ class DayArchiveViewTests(TestCase): res = self.client.get('/dates/booksignings/2008/apr/2/') self.assertEqual(res.status_code, 200) + @requires_tz_support @override_settings(USE_TZ=True, TIME_ZONE='Africa/Nairobi') def test_aware_datetime_day_view(self): bs = BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc)) @@ -578,6 +593,7 @@ class DateDetailViewTests(TestCase): res = self.client.get('/dates/booksignings/2008/apr/2/%d/' % bs.pk) self.assertEqual(res.status_code, 200) + @requires_tz_support @override_settings(USE_TZ=True, TIME_ZONE='Africa/Nairobi') def test_aware_datetime_date_detail(self): bs = BookSigning.objects.create(event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc))