Skip to content

Commit

Permalink
GH-3: Introduce IT page object for unauthorized page
Browse files Browse the repository at this point in the history
  • Loading branch information
markhobson committed Oct 12, 2023
1 parent a3d6034 commit 18a74dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions tests/integration/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from bs4 import BeautifulSoup, Tag
from flask.testing import FlaskClient
from werkzeug import Response as BaseResponse


class StartPage:
Expand All @@ -29,6 +30,24 @@ def __init__(self, tag: Tag):
self.home_url = cast(Tag, tag.find("a", class_="govuk-header__link"))["href"]


class UnauthorizedPage:
def __init__(self, client: FlaskClient):
self._client = client
self._response = BaseResponse()
self._soup = BeautifulSoup()

def open(self) -> UnauthorizedPage:
self._response = self._client.get("/auth/unauthorized")
self._soup = BeautifulSoup(self._response.text, "html.parser")
return self

def visible(self) -> bool:
return self._soup.h1.string == "Unauthorized" if self._soup.h1 else False

def is_unauthorized(self) -> bool:
return self._response.status_code == 401


class HomePage:
def __init__(self, client: FlaskClient):
self._client = client
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from flask import current_app, session
from flask.testing import FlaskClient

from tests.integration.pages import UnauthorizedPage


@pytest.fixture(name="config")
def config_fixture(config: Mapping[str, Any]) -> Mapping[str, Any]:
Expand Down Expand Up @@ -45,9 +47,9 @@ def test_callback_when_unauthorized_redirects_to_unauthorized(client: FlaskClien


def test_unauthorized(client: FlaskClient) -> None:
response = client.get("/auth/unauthorized")
unauthorized_page = UnauthorizedPage(client).open()

assert response.status_code == 401 and response.text == "<h1>Unauthorized</h1>"
assert unauthorized_page.visible() and unauthorized_page.is_unauthorized()


def test_logout_logs_out_from_oidc(client: FlaskClient) -> None:
Expand Down

0 comments on commit 18a74dd

Please sign in to comment.