From 0b50ee6721155ce0f652d4c1f47dcbb10c191894 Mon Sep 17 00:00:00 2001 From: Mike Date: Mon, 4 Dec 2023 17:48:36 -0800 Subject: [PATCH] Fix tests (#769) --- rest_framework_simplejwt/utils.py | 5 ++--- tests/test_init.py | 5 ++--- tests/test_utils.py | 11 ++++------- 3 files changed, 8 insertions(+), 13 deletions(-) Index: djangorestframework_simplejwt-5.3.1/rest_framework_simplejwt/utils.py =================================================================== --- djangorestframework_simplejwt-5.3.1.orig/rest_framework_simplejwt/utils.py +++ djangorestframework_simplejwt-5.3.1/rest_framework_simplejwt/utils.py @@ -5,7 +5,6 @@ from typing import Callable from django.conf import settings from django.utils.functional import lazy -from django.utils.timezone import is_naive, make_aware def get_md5_hash_password(password: str) -> str: @@ -16,8 +15,8 @@ def get_md5_hash_password(password: str) def make_utc(dt: datetime) -> datetime: - if settings.USE_TZ and is_naive(dt): - return make_aware(dt, timezone=timezone.utc) + if settings.USE_TZ and dt.tzinfo is None: + return dt.replace(tzinfo=timezone.utc) return dt Index: djangorestframework_simplejwt-5.3.1/tests/test_utils.py =================================================================== --- djangorestframework_simplejwt-5.3.1.orig/tests/test_utils.py +++ djangorestframework_simplejwt-5.3.1/tests/test_utils.py @@ -1,7 +1,6 @@ -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone from django.test import TestCase -from django.utils import timezone from freezegun import freeze_time from rest_framework_simplejwt.utils import ( @@ -24,11 +23,11 @@ class TestMakeUtc(TestCase): with self.settings(USE_TZ=False): dt = make_utc(dt) - self.assertTrue(timezone.is_naive(dt)) + self.assertTrue(dt.tzinfo is None) with self.settings(USE_TZ=True): dt = make_utc(dt) - self.assertTrue(timezone.is_aware(dt)) + self.assertTrue(dt.tzinfo is not None) self.assertEqual(dt.utcoffset(), timedelta(seconds=0)) @@ -39,9 +38,7 @@ class TestAwareUtcnow(TestCase): with freeze_time(now): # Should return aware utcnow if USE_TZ == True with self.settings(USE_TZ=True): - self.assertEqual( - timezone.make_aware(now, timezone=timezone.utc), aware_utcnow() - ) + self.assertEqual(now.replace(tzinfo=timezone.utc), aware_utcnow()) # Should return naive utcnow if USE_TZ == False with self.settings(USE_TZ=False):