Improved cookie support in the test client
This commit is contained in:
@@ -598,7 +598,7 @@ class Response:
|
||||
else: # pragma: no cover
|
||||
http_cookie += '; Expires=' + time.strftime(
|
||||
'%a, %d %b %Y %H:%M:%S GMT', expires.timetuple())
|
||||
if max_age:
|
||||
if max_age is not None:
|
||||
http_cookie += '; Max-Age=' + str(max_age)
|
||||
if secure:
|
||||
http_cookie += '; Secure'
|
||||
@@ -616,10 +616,10 @@ class Response:
|
||||
|
||||
:param cookie: The cookie's name.
|
||||
:param kwargs: Any cookie opens and flags supported by
|
||||
``set_cookie()`` except ``expires``.
|
||||
``set_cookie()`` except ``expires`` and ``max_age``.
|
||||
"""
|
||||
self.set_cookie(cookie, '', expires='Thu, 01 Jan 1970 00:00:01 GMT',
|
||||
**kwargs)
|
||||
max_age=0, **kwargs)
|
||||
|
||||
def complete(self):
|
||||
if isinstance(self.body, bytes) and \
|
||||
|
||||
@@ -141,7 +141,17 @@ class TestClient:
|
||||
cookie_options = cookie_value.split(';')
|
||||
delete = False
|
||||
for option in cookie_options[1:]:
|
||||
if option.strip().lower().startswith('expires='):
|
||||
if option.strip().lower().startswith(
|
||||
'max-age='): # pragma: no cover
|
||||
_, age = option.strip().split('=', 1)
|
||||
try:
|
||||
age = int(age)
|
||||
except ValueError: # pragma: no cover
|
||||
age = 0
|
||||
if age <= 0:
|
||||
delete = True
|
||||
break
|
||||
elif option.strip().lower().startswith('expires='):
|
||||
_, e = option.strip().split('=', 1)
|
||||
# this is a very limited parser for cookie expiry
|
||||
# that only detects a cookie deletion request when
|
||||
|
||||
@@ -203,7 +203,8 @@ class TestResponse(unittest.TestCase):
|
||||
'foo7=bar7; Path=/foo; Domain=example.com:1234; '
|
||||
'Expires=Tue, 05 Nov 2019 02:23:54 GMT; Max-Age=123; Secure; '
|
||||
'HttpOnly',
|
||||
'foo8=; Expires=Thu, 01 Jan 1970 00:00:01 GMT; HttpOnly',
|
||||
('foo8=; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Max-Age=0; '
|
||||
'HttpOnly'),
|
||||
]})
|
||||
|
||||
def test_redirect(self):
|
||||
|
||||
Reference in New Issue
Block a user