From fe0f506efc406306f807b0c1cfd4148c97668764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonel=20C=C3=A2mara?= Date: Mon, 3 Apr 2017 19:54:06 +0100 Subject: [PATCH] Create a CookieJar on __init__ instead of creating a new one each post Fixes #1505 --- gluon/contrib/webclient.py | 4 ++-- gluon/tests/test_web.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gluon/contrib/webclient.py b/gluon/contrib/webclient.py index 7f6e288b..6454e97f 100644 --- a/gluon/contrib/webclient.py +++ b/gluon/contrib/webclient.py @@ -43,6 +43,7 @@ class WebClient(object): self.forms = {} self.history = [] self.cookies = {} + self.cookiejar = cookielib.CookieJar() self.default_headers = default_headers self.sessions = {} self.session_regex = session_regex and re.compile(session_regex) @@ -79,9 +80,8 @@ class WebClient(object): cookies = cookies or {} headers = headers or {} - cj = cookielib.CookieJar() args = [ - urllib2.HTTPCookieProcessor(cj), + urllib2.HTTPCookieProcessor(self.cookiejar), urllib2.HTTPHandler(debuglevel=0) ] # if required do basic auth diff --git a/gluon/tests/test_web.py b/gluon/tests/test_web.py index adac0f28..c8f5be29 100644 --- a/gluon/tests/test_web.py +++ b/gluon/tests/test_web.py @@ -110,7 +110,7 @@ class TestWeb(LiveTest): self.assertTrue('Welcome Homer' in client.text) client = WebClient('http://127.0.0.1:8000/admin/default/') - client.post('index', data=dict(password='hello')) + client.post('index', data=dict(password='testpass')) client.get('site') client.get('design/welcome')