From b4cdcbf23937dfcba46d6b08996438a4078e03fd Mon Sep 17 00:00:00 2001 From: "Bernhard M. Wiedemann" Date: Mon, 16 Jan 2023 05:37:25 +0100 Subject: [PATCH] Removed hardcoded date in SetCookieTests.test_far_expiration(). Follow up to a92c83828785f12dcf90477413c2d04e1855fbb9. --- tests/responses/test_cookie.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/responses/test_cookie.py b/tests/responses/test_cookie.py index ea92584151..7e7f356deb 100644 --- a/tests/responses/test_cookie.py +++ b/tests/responses/test_cookie.py @@ -1,5 +1,6 @@ import time -from datetime import datetime, timedelta, timezone +from datetime import date, datetime, timedelta, timezone +from email.utils import format_datetime as format_datetime_rfc5322 from http import cookies from django.http import HttpResponse @@ -49,12 +50,18 @@ class SetCookieTests(SimpleTestCase): def test_far_expiration(self): """Cookie will expire when a distant expiration time is provided.""" response = HttpResponse() - response.set_cookie("datetime", expires=datetime(2038, 1, 1, 4, 5, 6)) + future_datetime = datetime( + date.today().year + 2, 1, 1, 4, 5, 6, tzinfo=timezone.utc + ) + response.set_cookie("datetime", expires=future_datetime) datetime_cookie = response.cookies["datetime"] self.assertIn( datetime_cookie["expires"], # assertIn accounts for slight time dependency (#23450) - ("Fri, 01 Jan 2038 04:05:06 GMT", "Fri, 01 Jan 2038 04:05:07 GMT"), + ( + format_datetime_rfc5322(future_datetime, usegmt=True), + format_datetime_rfc5322(future_datetime.replace(second=7), usegmt=True), + ), ) def test_max_age_expiration(self):