From c8e2f7591d6ea3545aeb32fa4c92cbeb9a622546 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 18 Mar 2012 20:58:22 +0000 Subject: Fixed #17931 -- Accepted aware datetimes to set cookies expiry dates. Thanks jaddison for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17766 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/requests/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py index d4239448dd..b7a4788ec5 100644 --- a/tests/regressiontests/requests/tests.py +++ b/tests/regressiontests/requests/tests.py @@ -12,6 +12,7 @@ from django.http import HttpRequest, HttpResponse, parse_cookie, build_request_r from django.test.utils import get_warnings_state, restore_warnings_state from django.utils import unittest from django.utils.http import cookie_date +from django.utils.timezone import utc class RequestsTests(unittest.TestCase): @@ -207,6 +208,15 @@ class RequestsTests(unittest.TestCase): datetime_cookie = response.cookies['datetime'] self.assertEqual(datetime_cookie['max-age'], 10) + def test_aware_expiration(self): + "Cookie accepts an aware datetime as expiration time" + response = HttpResponse() + expires = (datetime.utcnow() + timedelta(seconds=10)).replace(tzinfo=utc) + time.sleep(0.001) + response.set_cookie('datetime', expires=expires) + datetime_cookie = response.cookies['datetime'] + self.assertEqual(datetime_cookie['max-age'], 10) + def test_far_expiration(self): "Cookie will expire when an distant expiration time is provided" response = HttpResponse() -- cgit v1.3