diff options
| author | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-03-23 12:15:36 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-03-24 06:29:50 +0100 |
| commit | bb61f0186d5c490caa44f3e3672d81e14414d33c (patch) | |
| tree | 71e682d415e4640fd1e950af0e4921b2af57ea60 /tests | |
| parent | 1cf60ce6017d904024ee132f7edae0b4b821a954 (diff) | |
Refs #32365 -- Removed internal uses of utils.timezone.utc alias.
Remaining test case ensures that uses of the alias are mapped
canonically by the migration writer.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/aggregation/tests.py | 6 | ||||
| -rw-r--r-- | tests/auth_tests/test_remote_user.py | 3 | ||||
| -rw-r--r-- | tests/datatypes/tests.py | 3 | ||||
| -rw-r--r-- | tests/db_functions/datetime/test_extract_trunc.py | 9 | ||||
| -rw-r--r-- | tests/file_storage/tests.py | 5 | ||||
| -rw-r--r-- | tests/forms_tests/field_tests/test_datetimefield.py | 8 | ||||
| -rw-r--r-- | tests/generic_views/test_dates.py | 49 | ||||
| -rw-r--r-- | tests/humanize_tests/tests.py | 6 | ||||
| -rw-r--r-- | tests/migrations/test_writer.py | 2 | ||||
| -rw-r--r-- | tests/postgres_tests/test_ranges.py | 7 | ||||
| -rw-r--r-- | tests/responses/test_cookie.py | 9 | ||||
| -rw-r--r-- | tests/schema/tests.py | 3 | ||||
| -rw-r--r-- | tests/staticfiles_tests/storage.py | 3 | ||||
| -rw-r--r-- | tests/staticfiles_tests/test_management.py | 3 | ||||
| -rw-r--r-- | tests/timezones/tests.py | 6 | ||||
| -rw-r--r-- | tests/utils_tests/test_dateformat.py | 13 | ||||
| -rw-r--r-- | tests/utils_tests/test_feedgenerator.py | 7 |
17 files changed, 80 insertions, 62 deletions
diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 4ca8729a4b..b779fe551c 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -1847,7 +1847,7 @@ class AggregateTestCase(TestCase): ) def test_aggregation_default_using_time_from_database(self): - now = timezone.now().astimezone(timezone.utc) + now = timezone.now().astimezone(datetime.timezone.utc) expr = Min( "store__friday_night_closing", filter=~Q(store__name="Amazon.com"), @@ -1899,7 +1899,7 @@ class AggregateTestCase(TestCase): ) def test_aggregation_default_using_date_from_database(self): - now = timezone.now().astimezone(timezone.utc) + now = timezone.now().astimezone(datetime.timezone.utc) expr = Min("book__pubdate", default=TruncDate(NowUTC())) queryset = Publisher.objects.annotate(earliest_pubdate=expr).order_by("name") self.assertSequenceEqual( @@ -1960,7 +1960,7 @@ class AggregateTestCase(TestCase): ) def test_aggregation_default_using_datetime_from_database(self): - now = timezone.now().astimezone(timezone.utc) + now = timezone.now().astimezone(datetime.timezone.utc) expr = Min( "store__original_opening", filter=~Q(store__name="Amazon.com"), diff --git a/tests/auth_tests/test_remote_user.py b/tests/auth_tests/test_remote_user.py index 8fb1b972b5..9e6e0dce20 100644 --- a/tests/auth_tests/test_remote_user.py +++ b/tests/auth_tests/test_remote_user.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone from django.conf import settings from django.contrib.auth import authenticate @@ -13,7 +13,6 @@ from django.test import ( modify_settings, override_settings, ) -from django.utils import timezone from django.utils.deprecation import RemovedInDjango50Warning diff --git a/tests/datatypes/tests.py b/tests/datatypes/tests.py index 56f6c14c31..97f3ec0852 100644 --- a/tests/datatypes/tests.py +++ b/tests/datatypes/tests.py @@ -1,7 +1,6 @@ import datetime from django.test import TestCase, skipIfDBFeature -from django.utils.timezone import utc from .models import Donut, RumBaba @@ -94,7 +93,7 @@ class DataTypesTestCase(TestCase): def test_error_on_timezone(self): """Regression test for #8354: the MySQL and Oracle backends should raise an error if given a timezone-aware datetime object.""" - dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=utc) + dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=datetime.timezone.utc) d = Donut(name="Bear claw", consumed_at=dt) # MySQL backend does not support timezone-aware datetimes. with self.assertRaises(ValueError): diff --git a/tests/db_functions/datetime/test_extract_trunc.py b/tests/db_functions/datetime/test_extract_trunc.py index a01778c719..0c08ccf106 100644 --- a/tests/db_functions/datetime/test_extract_trunc.py +++ b/tests/db_functions/datetime/test_extract_trunc.py @@ -1606,7 +1606,7 @@ class DateFunctionTests(TestCase): outer = Author.objects.annotate( newest_fan_year=TruncYear(Subquery(inner, output_field=DateTimeField())) ) - tz = timezone.utc if settings.USE_TZ else None + tz = datetime_timezone.utc if settings.USE_TZ else None self.assertSequenceEqual( outer.order_by("name").values("name", "newest_fan_year"), [ @@ -1758,7 +1758,7 @@ class DateFunctionWithTimeZoneTests(DateFunctionTests): DTModel.objects.annotate( day_melb=Extract("start_datetime", "day"), day_utc=Extract( - "start_datetime", "day", tzinfo=timezone.utc + "start_datetime", "day", tzinfo=datetime_timezone.utc ), ) .order_by("start_datetime") @@ -1826,9 +1826,8 @@ class DateFunctionWithTimeZoneTests(DateFunctionTests): @ignore_warnings(category=RemovedInDjango50Warning) def test_trunc_ambiguous_and_invalid_times(self): sao = pytz.timezone("America/Sao_Paulo") - utc = timezone.utc - start_datetime = datetime(2016, 10, 16, 13, tzinfo=utc) - end_datetime = datetime(2016, 2, 21, 1, tzinfo=utc) + start_datetime = datetime(2016, 10, 16, 13, tzinfo=datetime_timezone.utc) + end_datetime = datetime(2016, 2, 21, 1, tzinfo=datetime_timezone.utc) self.create_model(start_datetime, end_datetime) with timezone.override(sao): with self.assertRaisesMessage( diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index f7bbb343d6..87a5e70c33 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -6,6 +6,7 @@ import threading import time import unittest from datetime import datetime, timedelta +from datetime import timezone as datetime_timezone from io import StringIO from pathlib import Path from urllib.request import urlopen @@ -168,7 +169,7 @@ class FileStorageTests(SimpleTestCase): naive_now = datetime.now() algiers_offset = now_in_algiers.tzinfo.utcoffset(naive_now) django_offset = timezone.get_current_timezone().utcoffset(naive_now) - utc_offset = timezone.utc.utcoffset(naive_now) + utc_offset = datetime_timezone.utc.utcoffset(naive_now) self.assertGreater(algiers_offset, utc_offset) self.assertLess(django_offset, utc_offset) @@ -199,7 +200,7 @@ class FileStorageTests(SimpleTestCase): naive_now = datetime.now() algiers_offset = now_in_algiers.tzinfo.utcoffset(naive_now) django_offset = timezone.get_current_timezone().utcoffset(naive_now) - utc_offset = timezone.utc.utcoffset(naive_now) + utc_offset = datetime_timezone.utc.utcoffset(naive_now) self.assertGreater(algiers_offset, utc_offset) self.assertLess(django_offset, utc_offset) diff --git a/tests/forms_tests/field_tests/test_datetimefield.py b/tests/forms_tests/field_tests/test_datetimefield.py index 3d266da6b7..af303b0436 100644 --- a/tests/forms_tests/field_tests/test_datetimefield.py +++ b/tests/forms_tests/field_tests/test_datetimefield.py @@ -1,9 +1,9 @@ -from datetime import date, datetime +from datetime import date, datetime, timezone from django.core.exceptions import ValidationError from django.forms import DateTimeField from django.test import SimpleTestCase -from django.utils.timezone import get_fixed_timezone, utc +from django.utils.timezone import get_fixed_timezone class DateTimeFieldTest(SimpleTestCase): @@ -40,7 +40,7 @@ class DateTimeFieldTest(SimpleTestCase): ("2014-09-23T22:34:41", datetime(2014, 9, 23, 22, 34, 41)), ("2014-09-23T22:34", datetime(2014, 9, 23, 22, 34)), ("2014-09-23", datetime(2014, 9, 23, 0, 0)), - ("2014-09-23T22:34Z", datetime(2014, 9, 23, 22, 34, tzinfo=utc)), + ("2014-09-23T22:34Z", datetime(2014, 9, 23, 22, 34, tzinfo=timezone.utc)), ( "2014-09-23T22:34+07:00", datetime(2014, 9, 23, 22, 34, tzinfo=get_fixed_timezone(420)), @@ -57,7 +57,7 @@ class DateTimeFieldTest(SimpleTestCase): " 2014-09-23T22:34:41.614804 ", datetime(2014, 9, 23, 22, 34, 41, 614804), ), - (" 2014-09-23T22:34Z ", datetime(2014, 9, 23, 22, 34, tzinfo=utc)), + (" 2014-09-23T22:34Z ", datetime(2014, 9, 23, 22, 34, tzinfo=timezone.utc)), ] f = DateTimeField() for value, expected_datetime in tests: diff --git a/tests/generic_views/test_dates.py b/tests/generic_views/test_dates.py index 9edcf8f688..90476270cc 100644 --- a/tests/generic_views/test_dates.py +++ b/tests/generic_views/test_dates.py @@ -4,7 +4,6 @@ from unittest import mock from django.core.exceptions import ImproperlyConfigured from django.test import TestCase, override_settings, skipUnlessDBFeature from django.test.utils import requires_tz_support -from django.utils import timezone from .models import Artist, Author, Book, BookSigning, Page @@ -157,7 +156,9 @@ class ArchiveIndexViewTests(TestDataMixin, TestCase): @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) + event_date=datetime.datetime( + 2008, 4, 2, 12, 0, tzinfo=datetime.timezone.utc + ) ) res = self.client.get("/dates/booksignings/") self.assertEqual(res.status_code, 200) @@ -344,7 +345,9 @@ class YearArchiveViewTests(TestDataMixin, TestCase): @override_settings(USE_TZ=True, TIME_ZONE="Africa/Nairobi") def test_aware_datetime_year_view(self): BookSigning.objects.create( - event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc) + event_date=datetime.datetime( + 2008, 4, 2, 12, 0, tzinfo=datetime.timezone.utc + ) ) res = self.client.get("/dates/booksignings/2008/") self.assertEqual(res.status_code, 200) @@ -517,13 +520,19 @@ class MonthArchiveViewTests(TestDataMixin, TestCase): @override_settings(USE_TZ=True, TIME_ZONE="Africa/Nairobi") def test_aware_datetime_month_view(self): BookSigning.objects.create( - event_date=datetime.datetime(2008, 2, 1, 12, 0, tzinfo=timezone.utc) + event_date=datetime.datetime( + 2008, 2, 1, 12, 0, tzinfo=datetime.timezone.utc + ) ) BookSigning.objects.create( - event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc) + event_date=datetime.datetime( + 2008, 4, 2, 12, 0, tzinfo=datetime.timezone.utc + ) ) BookSigning.objects.create( - event_date=datetime.datetime(2008, 6, 3, 12, 0, tzinfo=timezone.utc) + event_date=datetime.datetime( + 2008, 6, 3, 12, 0, tzinfo=datetime.timezone.utc + ) ) res = self.client.get("/dates/booksignings/2008/apr/") self.assertEqual(res.status_code, 200) @@ -664,7 +673,9 @@ class WeekArchiveViewTests(TestDataMixin, TestCase): @override_settings(USE_TZ=True, TIME_ZONE="Africa/Nairobi") def test_aware_datetime_week_view(self): BookSigning.objects.create( - event_date=datetime.datetime(2008, 4, 2, 12, 0, tzinfo=timezone.utc) + event_date=datetime.datetime( + 2008, 4, 2, 12, 0, tzinfo=datetime.timezone.utc + ) ) res = self.client.get("/dates/booksignings/2008/week/13/") self.assertEqual(res.status_code, 200) @@ -794,19 +805,25 @@ class DayArchiveViewTests(TestDataMixin, TestCase): @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) + event_date=datetime.datetime( + 2008, 4, 2, 12, 0, tzinfo=datetime.timezone.utc + ) ) res = self.client.get("/dates/booksignings/2008/apr/2/") self.assertEqual(res.status_code, 200) # 2008-04-02T00:00:00+03:00 (beginning of day) > # 2008-04-01T22:00:00+00:00 (book signing event date). - bs.event_date = datetime.datetime(2008, 4, 1, 22, 0, tzinfo=timezone.utc) + bs.event_date = datetime.datetime( + 2008, 4, 1, 22, 0, tzinfo=datetime.timezone.utc + ) bs.save() res = self.client.get("/dates/booksignings/2008/apr/2/") self.assertEqual(res.status_code, 200) # 2008-04-03T00:00:00+03:00 (end of day) > 2008-04-02T22:00:00+00:00 # (book signing event date). - bs.event_date = datetime.datetime(2008, 4, 2, 22, 0, tzinfo=timezone.utc) + bs.event_date = datetime.datetime( + 2008, 4, 2, 22, 0, tzinfo=datetime.timezone.utc + ) bs.save() res = self.client.get("/dates/booksignings/2008/apr/2/") self.assertEqual(res.status_code, 404) @@ -897,19 +914,25 @@ class DateDetailViewTests(TestDataMixin, TestCase): @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) + event_date=datetime.datetime( + 2008, 4, 2, 12, 0, tzinfo=datetime.timezone.utc + ) ) res = self.client.get("/dates/booksignings/2008/apr/2/%d/" % bs.pk) self.assertEqual(res.status_code, 200) # 2008-04-02T00:00:00+03:00 (beginning of day) > # 2008-04-01T22:00:00+00:00 (book signing event date). - bs.event_date = datetime.datetime(2008, 4, 1, 22, 0, tzinfo=timezone.utc) + bs.event_date = datetime.datetime( + 2008, 4, 1, 22, 0, tzinfo=datetime.timezone.utc + ) bs.save() res = self.client.get("/dates/booksignings/2008/apr/2/%d/" % bs.pk) self.assertEqual(res.status_code, 200) # 2008-04-03T00:00:00+03:00 (end of day) > 2008-04-02T22:00:00+00:00 # (book signing event date). - bs.event_date = datetime.datetime(2008, 4, 2, 22, 0, tzinfo=timezone.utc) + bs.event_date = datetime.datetime( + 2008, 4, 2, 22, 0, tzinfo=datetime.timezone.utc + ) bs.save() res = self.client.get("/dates/booksignings/2008/apr/2/%d/" % bs.pk) self.assertEqual(res.status_code, 404) diff --git a/tests/humanize_tests/tests.py b/tests/humanize_tests/tests.py index c98bab382d..432314f795 100644 --- a/tests/humanize_tests/tests.py +++ b/tests/humanize_tests/tests.py @@ -6,7 +6,7 @@ from django.template import Context, Template, defaultfilters from django.test import SimpleTestCase, modify_settings, override_settings from django.utils import translation from django.utils.html import escape -from django.utils.timezone import get_fixed_timezone, utc +from django.utils.timezone import get_fixed_timezone from django.utils.translation import gettext as _ # Mock out datetime in some tests so they don't fail occasionally when they @@ -359,7 +359,7 @@ class HumanizeTests(SimpleTestCase): def test_naturalday_uses_localtime(self): # Regression for #18504 # This is 2012-03-08HT19:30:00-06:00 in America/Chicago - dt = datetime.datetime(2012, 3, 9, 1, 30, tzinfo=utc) + dt = datetime.datetime(2012, 3, 9, 1, 30, tzinfo=datetime.timezone.utc) orig_humanize_datetime, humanize.datetime = humanize.datetime, MockDateTime try: @@ -396,7 +396,7 @@ class HumanizeTests(SimpleTestCase): now + datetime.timedelta(days=2, hours=6), now + datetime.timedelta(days=500), now.replace(tzinfo=naive()), - now.replace(tzinfo=utc), + now.replace(tzinfo=datetime.timezone.utc), ] result_list = [ "test", diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py index 07a2db989c..3e95ca6c15 100644 --- a/tests/migrations/test_writer.py +++ b/tests/migrations/test_writer.py @@ -909,7 +909,7 @@ class WriterTests(SimpleTestCase): Test comments at top of file. """ migration = type("Migration", (migrations.Migration,), {"operations": []}) - dt = datetime.datetime(2015, 7, 31, 4, 40, 0, 0, tzinfo=utc) + dt = datetime.datetime(2015, 7, 31, 4, 40, 0, 0, tzinfo=datetime.timezone.utc) with mock.patch("django.db.migrations.writer.now", lambda: dt): for include_header in (True, False): with self.subTest(include_header=include_header): diff --git a/tests/postgres_tests/test_ranges.py b/tests/postgres_tests/test_ranges.py index aaef47d6be..86722a9f46 100644 --- a/tests/postgres_tests/test_ranges.py +++ b/tests/postgres_tests/test_ranges.py @@ -563,8 +563,8 @@ class TestSerialization(PostgreSQLSimpleTestCase): lower_date = datetime.date(2014, 1, 1) upper_date = datetime.date(2014, 2, 2) - lower_dt = datetime.datetime(2014, 1, 1, 0, 0, 0, tzinfo=timezone.utc) - upper_dt = datetime.datetime(2014, 2, 2, 12, 12, 12, tzinfo=timezone.utc) + lower_dt = datetime.datetime(2014, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc) + upper_dt = datetime.datetime(2014, 2, 2, 12, 12, 12, tzinfo=datetime.timezone.utc) def test_dumping(self): instance = RangesModel( @@ -991,7 +991,8 @@ class TestFormField(PostgreSQLSimpleTestCase): field = pg_forms.DateTimeRangeField() value = field.prepare_value( DateTimeTZRange( - datetime.datetime(2015, 5, 22, 16, 6, 33, tzinfo=timezone.utc), None + datetime.datetime(2015, 5, 22, 16, 6, 33, tzinfo=datetime.timezone.utc), + None, ) ) self.assertEqual(value, [datetime.datetime(2015, 5, 22, 18, 6, 33), None]) diff --git a/tests/responses/test_cookie.py b/tests/responses/test_cookie.py index b6610cbaab..ea92584151 100644 --- a/tests/responses/test_cookie.py +++ b/tests/responses/test_cookie.py @@ -1,12 +1,11 @@ import time -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from http import cookies from django.http import HttpResponse from django.test import SimpleTestCase from django.test.utils import freeze_time from django.utils.http import http_date -from django.utils.timezone import utc class SetCookieTests(SimpleTestCase): @@ -18,7 +17,9 @@ class SetCookieTests(SimpleTestCase): # evaluated expiration time and the time evaluated in set_cookie(). If # this difference doesn't exist, the cookie time will be 1 second # larger. The sleep guarantees that there will be a time difference. - expires = datetime.now(tz=utc).replace(tzinfo=None) + timedelta(seconds=10) + expires = datetime.now(tz=timezone.utc).replace(tzinfo=None) + timedelta( + seconds=10 + ) time.sleep(0.001) response.set_cookie("datetime", expires=expires) datetime_cookie = response.cookies["datetime"] @@ -27,7 +28,7 @@ class SetCookieTests(SimpleTestCase): def test_aware_expiration(self): """set_cookie() accepts an aware datetime as expiration time.""" response = HttpResponse() - expires = datetime.now(tz=utc) + timedelta(seconds=10) + expires = datetime.now(tz=timezone.utc) + timedelta(seconds=10) time.sleep(0.001) response.set_cookie("datetime", expires=expires) datetime_cookie = response.cookies["datetime"] diff --git a/tests/schema/tests.py b/tests/schema/tests.py index 076663e049..d9e59d32dc 100644 --- a/tests/schema/tests.py +++ b/tests/schema/tests.py @@ -55,7 +55,6 @@ from django.db.models.indexes import IndexExpression from django.db.transaction import TransactionManagementError, atomic from django.test import TransactionTestCase, skipIfDBFeature, skipUnlessDBFeature from django.test.utils import CaptureQueriesContext, isolate_apps, register_lookup -from django.utils import timezone from .fields import CustomManyToManyField, InheritedManyToManyField, MediumBlobField from .models import ( @@ -4231,7 +4230,7 @@ class SchemaTests(TransactionTestCase): """ now = datetime.datetime(month=1, day=1, year=2000, hour=1, minute=1) now_tz = datetime.datetime( - month=1, day=1, year=2000, hour=1, minute=1, tzinfo=timezone.utc + month=1, day=1, year=2000, hour=1, minute=1, tzinfo=datetime.timezone.utc ) mocked_datetime.now = mock.MagicMock(return_value=now) mocked_tz.now = mock.MagicMock(return_value=now_tz) diff --git a/tests/staticfiles_tests/storage.py b/tests/staticfiles_tests/storage.py index 1bb4e37485..51614fbb18 100644 --- a/tests/staticfiles_tests/storage.py +++ b/tests/staticfiles_tests/storage.py @@ -1,10 +1,9 @@ import os -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from django.conf import settings from django.contrib.staticfiles.storage import ManifestStaticFilesStorage from django.core.files import storage -from django.utils import timezone class DummyStorage(storage.Storage): diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py index 09ce7c488c..6dec3a67bd 100644 --- a/tests/staticfiles_tests/test_management.py +++ b/tests/staticfiles_tests/test_management.py @@ -17,7 +17,6 @@ from django.core.management import CommandError, call_command from django.core.management.base import SystemCheckError from django.test import RequestFactory, override_settings from django.test.utils import extend_sys_path -from django.utils import timezone from django.utils._os import symlinks_supported from django.utils.functional import empty @@ -531,7 +530,7 @@ class TestCollectionNonLocalStorage(TestNoFilesCreated, CollectionTestCase): storage = DummyStorage() self.assertEqual( storage.get_modified_time("name"), - datetime.datetime(1970, 1, 1, tzinfo=timezone.utc), + datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc), ) with self.assertRaisesMessage( NotImplementedError, "This backend doesn't support absolute paths." diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py index 75c79ecfdd..4e26516041 100644 --- a/tests/timezones/tests.py +++ b/tests/timezones/tests.py @@ -75,7 +75,7 @@ except ImportError: # datetime.datetime(2011, 9, 1, 13, 20, 30), which translates to # 10:20:30 in UTC and 17:20:30 in ICT. -UTC = timezone.utc +UTC = datetime.timezone.utc EAT = timezone.get_fixed_timezone(180) # Africa/Nairobi ICT = timezone.get_fixed_timezone(420) # Asia/Bangkok @@ -651,7 +651,7 @@ class NewDatabaseTests(TestCase): @skipIfDBFeature("supports_timezones") def test_cursor_execute_accepts_naive_datetime(self): dt = datetime.datetime(2011, 9, 1, 13, 20, 30, tzinfo=EAT) - utc_naive_dt = timezone.make_naive(dt, timezone.utc) + utc_naive_dt = timezone.make_naive(dt, datetime.timezone.utc) with connection.cursor() as cursor: cursor.execute( "INSERT INTO timezones_event (dt) VALUES (%s)", [utc_naive_dt] @@ -670,7 +670,7 @@ class NewDatabaseTests(TestCase): @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) + utc_naive_dt = timezone.make_naive(dt, datetime.timezone.utc) Event.objects.create(dt=dt) with connection.cursor() as cursor: cursor.execute( diff --git a/tests/utils_tests/test_dateformat.py b/tests/utils_tests/test_dateformat.py index 4e4926c85b..4402048f3a 100644 --- a/tests/utils_tests/test_dateformat.py +++ b/tests/utils_tests/test_dateformat.py @@ -1,15 +1,10 @@ -from datetime import date, datetime, time, tzinfo +from datetime import date, datetime, time, timezone, tzinfo from django.test import SimpleTestCase, override_settings from django.test.utils import TZ_SUPPORT, requires_tz_support from django.utils import dateformat, translation from django.utils.dateformat import format -from django.utils.timezone import ( - get_default_timezone, - get_fixed_timezone, - make_aware, - utc, -) +from django.utils.timezone import get_default_timezone, get_fixed_timezone, make_aware @override_settings(TIME_ZONE="Europe/Copenhagen") @@ -71,7 +66,7 @@ class DateFormatTests(SimpleTestCase): ) def test_epoch(self): - udt = datetime(1970, 1, 1, tzinfo=utc) + udt = datetime(1970, 1, 1, tzinfo=timezone.utc) self.assertEqual(format(udt, "U"), "0") def test_empty_format(self): @@ -216,7 +211,7 @@ class DateFormatTests(SimpleTestCase): @requires_tz_support def test_e_format_with_named_time_zone(self): - dt = datetime(1970, 1, 1, tzinfo=utc) + dt = datetime(1970, 1, 1, tzinfo=timezone.utc) self.assertEqual(dateformat.format(dt, "e"), "UTC") @requires_tz_support diff --git a/tests/utils_tests/test_feedgenerator.py b/tests/utils_tests/test_feedgenerator.py index 90deb2ddf2..ee15b6e928 100644 --- a/tests/utils_tests/test_feedgenerator.py +++ b/tests/utils_tests/test_feedgenerator.py @@ -2,7 +2,7 @@ import datetime from django.test import SimpleTestCase from django.utils import feedgenerator -from django.utils.timezone import get_fixed_timezone, utc +from django.utils.timezone import get_fixed_timezone class FeedgeneratorTests(SimpleTestCase): @@ -144,4 +144,7 @@ class FeedgeneratorTests(SimpleTestCase): for use_tz in (True, False): with self.settings(USE_TZ=use_tz): rss_feed = feedgenerator.Rss201rev2Feed("title", "link", "description") - self.assertEqual(rss_feed.latest_post_date().tzinfo, utc) + self.assertEqual( + rss_feed.latest_post_date().tzinfo, + datetime.timezone.utc, + ) |
