morethantext-web/tests/step_defs/page.py

34 lines
840 B
Python

"""Fisture class for page functions."""
from http.cookiejar import CookieJar
from urllib import request
from urllib.error import HTTPError
class Page:
"""Class for getting an individual 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 = self.opener.open(url)
except HTTPError as err:
self.res = err
else:
with page:
self.res = page
def get_status_code(self):
"""Return the status code."""
return self.res.status
def get_cookies(self):
"""Did a session id get set."""
return self.cjar