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