1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

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
This commit is contained in:
Aymeric Augustin
2012-03-18 20:58:22 +00:00
parent c7cc4cfb9e
commit c8e2f7591d
2 changed files with 19 additions and 3 deletions

View File

@@ -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()