1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #29546 -- Deprecated django.utils.timezone.FixedOffset.

This commit is contained in:
Sergey Fedoseev
2018-07-10 01:33:36 +05:00
committed by Tim Graham
parent 8b1d361f28
commit 338f741c5e
7 changed files with 38 additions and 12 deletions

View File

@@ -4,8 +4,9 @@ from unittest import mock
import pytz
from django.test import SimpleTestCase, override_settings
from django.test import SimpleTestCase, ignore_warnings, override_settings
from django.utils import timezone
from django.utils.deprecation import RemovedInDjango31Warning
CET = pytz.timezone("Europe/Paris")
EAT = timezone.get_fixed_timezone(180) # Africa/Nairobi
@@ -97,7 +98,7 @@ class TimezoneTests(SimpleTestCase):
self.assertEqual(timezone.get_current_timezone_name(), 'Asia/Bangkok')
def test_override_fixed_offset(self):
with timezone.override(timezone.FixedOffset(0, 'tzname')):
with timezone.override(datetime.timezone(datetime.timedelta(), 'tzname')):
self.assertEqual(timezone.get_current_timezone_name(), 'tzname')
def test_activate_invalid_timezone(self):
@@ -196,11 +197,18 @@ class TimezoneTests(SimpleTestCase):
def test_fixedoffset_timedelta(self):
delta = datetime.timedelta(hours=1)
self.assertEqual(timezone.get_fixed_timezone(delta).utcoffset(''), delta)
self.assertEqual(timezone.get_fixed_timezone(delta).utcoffset(None), delta)
def test_fixedoffset_negative_timedelta(self):
delta = datetime.timedelta(hours=-2)
self.assertEqual(timezone.get_fixed_timezone(delta).utcoffset(''), delta)
self.assertEqual(timezone.get_fixed_timezone(delta).utcoffset(None), delta)
@ignore_warnings(category=RemovedInDjango31Warning)
def test_fixedoffset_pickle(self):
self.assertEqual(pickle.loads(pickle.dumps(timezone.FixedOffset(0, 'tzname'))).tzname(''), 'tzname')
def test_fixedoffset_deprecation(self):
msg = 'FixedOffset is deprecated in favor of datetime.timezone'
with self.assertWarnsMessage(RemovedInDjango31Warning, msg) as cm:
timezone.FixedOffset()
self.assertEqual(cm.filename, __file__)