diff options
| author | Tim Graham <timograham@gmail.com> | 2016-10-07 21:06:49 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-10-27 08:53:20 -0400 |
| commit | 414ad25b090a63eaaf297b1164c8f7d814a710a2 (patch) | |
| tree | e3d0e6fdffee0793baad41a339c2d63db742c33a /tests/timezones | |
| parent | d84ffcc22b2a0dbc0a44a67d56da7e3647e2f87a (diff) | |
| download | django-414ad25b090a63eaaf297b1164c8f7d814a710a2.tar.gz | |
Fixed #27327 -- Simplified time zone handling by requiring pytz.
Diffstat (limited to 'tests/timezones')
| -rw-r--r-- | tests/timezones/tests.py | 32 |
1 files changed, 5 insertions, 27 deletions
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py index e72fff069b..d95877d227 100644 --- a/tests/timezones/tests.py +++ b/tests/timezones/tests.py @@ -8,6 +8,8 @@ from contextlib import contextmanager from unittest import SkipTest, skipIf from xml.dom.minidom import parseString +import pytz + from django.contrib.auth.models import User from django.core import serializers from django.core.exceptions import ImproperlyConfigured @@ -33,13 +35,6 @@ from .models import ( AllDayEvent, Event, MaybeEvent, Session, SessionEvent, Timestamp, ) -try: - import pytz -except ImportError: - pytz = None - -requires_pytz = skipIf(pytz is None, "this test requires pytz") - # These tests use the EAT (Eastern Africa Time) and ICT (Indochina Time) # who don't have Daylight Saving Time, so we can represent them easily # with FixedOffset, and use them directly as tzinfo in the constructors. @@ -363,7 +358,6 @@ class NewDatabaseTests(TestCase): self.assertEqual(Event.objects.filter(dt__gte=dt2).count(), 1) self.assertEqual(Event.objects.filter(dt__gt=dt2).count(), 0) - @requires_pytz def test_query_filter_with_pytz_timezones(self): tz = pytz.timezone('Europe/Paris') dt = datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=tz) @@ -908,7 +902,6 @@ class TemplateTests(SimpleTestCase): expected = results[k1][k2] self.assertEqual(actual, expected, '%s / %s: %r != %r' % (k1, k2, actual, expected)) - @requires_pytz def test_localtime_filters_with_pytz(self): """ Test the |localtime, |utc, and |timezone filters with pytz. @@ -976,7 +969,6 @@ class TemplateTests(SimpleTestCase): "2011-09-01T13:20:30+03:00|2011-09-01T17:20:30+07:00|2011-09-01T13:20:30+03:00" ) - @requires_pytz def test_timezone_templatetag_with_pytz(self): """ Test the {% timezone %} templatetag with pytz. @@ -996,7 +988,7 @@ class TemplateTests(SimpleTestCase): def test_timezone_templatetag_invalid_argument(self): with self.assertRaises(TemplateSyntaxError): Template("{% load tz %}{% timezone %}{% endtimezone %}").render() - with self.assertRaises(ValueError if pytz is None else pytz.UnknownTimeZoneError): + with self.assertRaises(pytz.UnknownTimeZoneError): Template("{% load tz %}{% timezone tz %}{% endtimezone %}").render(Context({'tz': 'foobar'})) @skipIf(sys.platform.startswith('win'), "Windows uses non-standard time zone names") @@ -1006,7 +998,7 @@ class TemplateTests(SimpleTestCase): """ tpl = Template("{% load tz %}{% get_current_timezone as time_zone %}{{ time_zone }}") - self.assertEqual(tpl.render(Context()), "Africa/Nairobi" if pytz else "EAT") + self.assertEqual(tpl.render(Context()), "Africa/Nairobi") with timezone.override(UTC): self.assertEqual(tpl.render(Context()), "UTC") @@ -1019,7 +1011,6 @@ class TemplateTests(SimpleTestCase): with timezone.override(UTC): self.assertEqual(tpl.render(Context({'tz': ICT})), "+0700") - @requires_pytz def test_get_current_timezone_templatetag_with_pytz(self): """ Test the {% get_current_timezone %} templatetag with pytz. @@ -1048,7 +1039,7 @@ class TemplateTests(SimpleTestCase): context = Context() self.assertEqual(tpl.render(context), "") request_context = RequestContext(HttpRequest(), processors=[context_processors.tz]) - self.assertEqual(tpl.render(request_context), "Africa/Nairobi" if pytz else "EAT") + self.assertEqual(tpl.render(request_context), "Africa/Nairobi") @requires_tz_support def test_date_and_time_template_filters(self): @@ -1068,15 +1059,6 @@ class TemplateTests(SimpleTestCase): with timezone.override(ICT): self.assertEqual(tpl.render(ctx), "2011-09-01 at 20:20:20") - def test_localtime_with_time_zone_setting_set_to_none(self): - # Regression for #17274 - tpl = Template("{% load tz %}{{ dt }}") - ctx = Context({'dt': datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT)}) - - with self.settings(TIME_ZONE=None): - # the actual value depends on the system time zone of the host - self.assertTrue(tpl.render(ctx).startswith("2011")) - @requires_tz_support def test_now_template_tag_uses_current_time_zone(self): # Regression for #17343 @@ -1094,7 +1076,6 @@ class LegacyFormsTests(TestCase): self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 9, 1, 13, 20, 30)) - @requires_pytz def test_form_with_non_existent_time(self): form = EventForm({'dt': '2011-03-27 02:30:00'}) with timezone.override(pytz.timezone('Europe/Paris')): @@ -1102,7 +1083,6 @@ class LegacyFormsTests(TestCase): self.assertTrue(form.is_valid()) self.assertEqual(form.cleaned_data['dt'], datetime.datetime(2011, 3, 27, 2, 30, 0)) - @requires_pytz def test_form_with_ambiguous_time(self): form = EventForm({'dt': '2011-10-30 02:30:00'}) with timezone.override(pytz.timezone('Europe/Paris')): @@ -1141,7 +1121,6 @@ class NewFormsTests(TestCase): # Datetime inputs formats don't allow providing a time zone. self.assertFalse(form.is_valid()) - @requires_pytz def test_form_with_non_existent_time(self): with timezone.override(pytz.timezone('Europe/Paris')): form = EventForm({'dt': '2011-03-27 02:30:00'}) @@ -1153,7 +1132,6 @@ class NewFormsTests(TestCase): ] ) - @requires_pytz def test_form_with_ambiguous_time(self): with timezone.override(pytz.timezone('Europe/Paris')): form = EventForm({'dt': '2011-10-30 02:30:00'}) |
