summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2022-03-04 12:57:10 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-03-07 07:57:14 +0100
commitae2da5ba652c1a11cd88dcb119744dcecaeb03ee (patch)
tree5f79e182a07457487abe2f0108a2f1f65ad8a72d /tests
parent1882f6567df361f52e53b555b2faa677361e128a (diff)
Fixed #33562 -- Made HttpResponse.set_cookie() support timedelta for the max_age argument.
Diffstat (limited to 'tests')
-rw-r--r--tests/responses/test_cookie.py5
-rw-r--r--tests/signed_cookies_tests/tests.py7
2 files changed, 12 insertions, 0 deletions
diff --git a/tests/responses/test_cookie.py b/tests/responses/test_cookie.py
index b37c6fb7b6..3a57dcfe45 100644
--- a/tests/responses/test_cookie.py
+++ b/tests/responses/test_cookie.py
@@ -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)
diff --git a/tests/signed_cookies_tests/tests.py b/tests/signed_cookies_tests/tests.py
index a7ad0c0d84..876887d883 100644
--- a/tests/signed_cookies_tests/tests.py
+++ b/tests/signed_cookies_tests/tests.py
@@ -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()