Altered page to retain cookies.
This commit is contained in:
parent
c8680b33d4
commit
4f29abc818
@ -1,5 +1,6 @@
|
||||
"""Fisture class for page functions."""
|
||||
|
||||
from http.cookiejar import CookieJar
|
||||
from urllib import request
|
||||
from urllib.error import HTTPError
|
||||
|
||||
@ -10,11 +11,14 @@ class Page:
|
||||
def __init__(self):
|
||||
"""Init function."""
|
||||
self.res = None
|
||||
self.cjar = CookieJar()
|
||||
self.opener = request.build_opener(request.HTTPCookieProcessor(self.cjar))
|
||||
|
||||
def request_url(self, url):
|
||||
"""Make a page request."""
|
||||
try:
|
||||
page = request.urlopen(url)
|
||||
# page = request.urlopen(url)
|
||||
page = self.opener.open(url)
|
||||
except HTTPError as err:
|
||||
self.res = err
|
||||
else:
|
||||
@ -25,6 +29,6 @@ class Page:
|
||||
"""Return the status code."""
|
||||
return self.res.status
|
||||
|
||||
def get_header(self, header):
|
||||
def get_cookies(self):
|
||||
"""Did a session id get set."""
|
||||
return self.res.headers[header]
|
||||
return self.cjar
|
||||
|
@ -22,4 +22,4 @@ def access_home_page(server, page):
|
||||
@then("there is a session id")
|
||||
def confirm_session(page):
|
||||
"""Confirm session id exists."""
|
||||
assert page.get_header("set-cookie")
|
||||
assert len(page.get_cookies()), "No cookies received."
|
||||
|
Loading…
Reference in New Issue
Block a user