Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move playwright tests to dedicated e2e tests folder #14

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Unit Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
unit_test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.11

- name: Install Poetry
run: pip install poetry

- name: Install dependencies
run: poetry install

- name: Run Pytest tests
run: poetry run pytest --cov=app/main --cov-report term-missing -vvv app/tests/
20 changes: 8 additions & 12 deletions app/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from app.main import bp
from app.main.forms import CookiesForm

from app.data.data import consignment_response, consignment_files_response
# from app.data.data import consignment_response, consignment_files_response
anthonyhashemi marked this conversation as resolved.
Show resolved Hide resolved

from keycloak import KeycloakOpenID

Expand Down Expand Up @@ -58,10 +58,6 @@
]


# Get WellKnown
config_well_known = keycloak_openid.well_known()


@bp.route("/", methods=["GET"])
def index():
return render_template("index.html")
Expand Down Expand Up @@ -153,13 +149,13 @@ def quick_access():
return render_template("quick-access.html")


@bp.route("/record", methods=["GET"])
def record():
return render_template(
"record.html",
consignment=consignment_response,
consignment_files=consignment_files_response,
)
# @bp.route("/record", methods=["GET"])
anthonyhashemi marked this conversation as resolved.
Show resolved Hide resolved
# def record():
# return render_template(
# "record.html",
# consignment=consignment_response,
# consignment_files=consignment_files_response,
# )


@bp.route("/all-departments", methods=["GET"])
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions app/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from app import create_app


@pytest.fixture
def app():
app = create_app()
app.config["TESTING"] = True
app.config["WTF_CSRF_ENABLED"] = False
yield app


@pytest.fixture
def client(app):
return app.test_client()
19 changes: 0 additions & 19 deletions app/tests/test_example.py

This file was deleted.

Empty file removed app/tests/test_login.py
Empty file.
17 changes: 0 additions & 17 deletions app/tests/test_record_metadata.py

This file was deleted.

15 changes: 15 additions & 0 deletions app/tests/test_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask.testing import FlaskClient


def test_poc_search_get(client: FlaskClient):
anthonyhashemi marked this conversation as resolved.
Show resolved Hide resolved
"""
Given a user accessing the search page
When they make a GET request
Then they should see the search form and page content.
"""
response = client.get("/poc-search-view", follow_redirects=True)

assert response.status_code == 200
assert b"Search design PoC" in response.data
assert b"Search for digital records" in response.data
assert b"Search" in response.data
18 changes: 9 additions & 9 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


class Config(object):
CONTACT_EMAIL = os.environ.get("CONTACT_EMAIL")
CONTACT_PHONE = os.environ.get("CONTACT_PHONE")
DEPARTMENT_NAME = os.environ.get("DEPARTMENT_NAME")
DEPARTMENT_URL = os.environ.get("DEPARTMENT_URL")
CONTACT_EMAIL = os.environ.get("CONTACT_EMAIL", "")
anthonyhashemi marked this conversation as resolved.
Show resolved Hide resolved
CONTACT_PHONE = os.environ.get("CONTACT_PHONE", "")
DEPARTMENT_NAME = os.environ.get("DEPARTMENT_NAME", "")
DEPARTMENT_URL = os.environ.get("DEPARTMENT_URL", "")
RATELIMIT_HEADERS_ENABLED = True
RATELIMIT_STORAGE_URI = os.environ.get("REDIS_URL")
SECRET_KEY = os.environ.get("SECRET_KEY")
SERVICE_NAME = os.environ.get("SERVICE_NAME")
SERVICE_PHASE = os.environ.get("SERVICE_PHASE")
SERVICE_URL = os.environ.get("SERVICE_URL")
RATELIMIT_STORAGE_URI = os.environ.get("REDIS_URL", "")
SECRET_KEY = os.environ.get("SECRET_KEY", "")
SERVICE_NAME = os.environ.get("SERVICE_NAME", "")
SERVICE_PHASE = os.environ.get("SERVICE_PHASE", "")
SERVICE_URL = os.environ.get("SERVICE_URL", "")
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SECURE = True
File renamed without changes.
2 changes: 1 addition & 1 deletion app/tests/test_homepage.py → e2e_tests/test_homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


def test_has_title(page: Page):
page.goto("http://localhost:5000/")
page.goto("/")
anthonyhashemi marked this conversation as resolved.
Show resolved Hide resolved
anthonyhashemi marked this conversation as resolved.
Show resolved Hide resolved

# Expect a title "to contain" a substring.
expect(page).to_have_title(re.compile("AYR - Access Your Records – GOV.UK"))
17 changes: 17 additions & 0 deletions e2e_tests/test_record_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# import re
# from playwright.sync_api import Page, expect


# def test_page_title_and_header(page: Page):
anthonyhashemi marked this conversation as resolved.
Show resolved Hide resolved
# page.goto("/record")
# expect(page).to_have_title(
# re.compile("Record – AYR - Access Your Records – GOV.UK")
# )
# expect(page.get_by_text("Record metadata")).to_be_visible()


# def test_back_link(page: Page):
# page.goto("/record")
# page.get_by_role("link", name="Back", exact=True).click()
# page.wait_for_url("/")
# page.close()
37 changes: 15 additions & 22 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ python-dotenv = "1.0.0"
redis = "5.0.1"
python-keycloak = "3.3.0"
pytest-playwright = "0.4.3"
flask-pytest = "^0.0.5"

[tool.poetry.group.dev.dependencies]
bandit = "1.7.5"
Expand Down
Loading