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

Fixed #33562 -- Made HttpResponse.set_cookie() support timedelta for the max_age argument.

This commit is contained in:
Luke Plant
2022-03-04 12:57:10 +00:00
committed by Mariusz Felisiak
parent 1882f6567d
commit ae2da5ba65
5 changed files with 29 additions and 4 deletions

View File

@@ -71,6 +71,11 @@ class SetCookieTests(SimpleTestCase):
response.set_cookie("max_age", max_age=10.6)
self.assertEqual(response.cookies["max_age"]["max-age"], 10)
def test_max_age_timedelta(self):
response = HttpResponse()
response.set_cookie("max_age", max_age=timedelta(hours=1))
self.assertEqual(response.cookies["max_age"]["max-age"], 3600)
def test_httponly_cookie(self):
response = HttpResponse()
response.set_cookie("example", httponly=True)

View File

@@ -62,6 +62,13 @@ class SignedCookieTest(SimpleTestCase):
with self.assertRaises(signing.SignatureExpired):
request.get_signed_cookie("c", max_age=timedelta(seconds=10))
def test_set_signed_cookie_max_age_argument(self):
response = HttpResponse()
response.set_signed_cookie("c", "value", max_age=100)
self.assertEqual(response.cookies["c"]["max-age"], 100)
response.set_signed_cookie("d", "value", max_age=timedelta(hours=2))
self.assertEqual(response.cookies["d"]["max-age"], 7200)
@override_settings(SECRET_KEY=b"\xe7")
def test_signed_cookies_with_binary_key(self):
response = HttpResponse()