summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlton Gibson <carlton.gibson@noumenal.es>2022-03-24 11:09:55 +0100
committerCarlton Gibson <carlton@noumenal.es>2022-03-29 14:47:44 +0200
commit59ab3fd0e9e606d7f0f7ca26609c06ee679ece97 (patch)
tree9014f24e170c210492e65fe54bcbf236e7342c4a /tests
parentbaf9604ed8fed3e6e7ddfaca2d83c377c81399ae (diff)
Refs #32365 -- Deprecated django.utils.timezone.utc.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_writer.py7
-rw-r--r--tests/timezones/tests.py13
2 files changed, 18 insertions, 2 deletions
diff --git a/tests/migrations/test_writer.py b/tests/migrations/test_writer.py
index 3e95ca6c15..6ec6d938b9 100644
--- a/tests/migrations/test_writer.py
+++ b/tests/migrations/test_writer.py
@@ -29,10 +29,11 @@ from django.core.validators import EmailValidator, RegexValidator
from django.db import migrations, models
from django.db.migrations.serializer import BaseSerializer
from django.db.migrations.writer import MigrationWriter, OperationWriter
-from django.test import SimpleTestCase
+from django.test import SimpleTestCase, ignore_warnings
from django.utils.deconstruct import deconstructible
+from django.utils.deprecation import RemovedInDjango50Warning
from django.utils.functional import SimpleLazyObject
-from django.utils.timezone import get_default_timezone, get_fixed_timezone, utc
+from django.utils.timezone import get_default_timezone, get_fixed_timezone
from django.utils.translation import gettext_lazy as _
from .models import FoodManager, FoodQuerySet
@@ -532,6 +533,8 @@ class WriterTests(SimpleTestCase):
datetime.datetime(2014, 1, 1, 1, 1),
("datetime.datetime(2014, 1, 1, 1, 1)", {"import datetime"}),
)
+ with ignore_warnings(category=RemovedInDjango50Warning):
+ from django.utils.timezone import utc
for tzinfo in (utc, datetime.timezone.utc):
with self.subTest(tzinfo=tzinfo):
self.assertSerializedResultEqual(
diff --git a/tests/timezones/tests.py b/tests/timezones/tests.py
index 4e26516041..f2617f4d0f 100644
--- a/tests/timezones/tests.py
+++ b/tests/timezones/tests.py
@@ -88,6 +88,19 @@ def get_timezones(key):
return [constructor(key) for constructor in ZONE_CONSTRUCTORS]
+class UTCAliasTests(SimpleTestCase):
+ def test_alias_deprecation_warning(self):
+ msg = (
+ "The django.utils.timezone.utc alias is deprecated. "
+ "Please update your code to use datetime.timezone.utc instead."
+ )
+ with self.assertRaisesMessage(RemovedInDjango50Warning, msg):
+ timezone.utc
+
+ def test_timezone_module_dir_includes_utc(self):
+ self.assertIn("utc", dir(timezone))
+
+
@contextmanager
def override_database_connection_timezone(timezone):
try: