Skip to content

Commit

Permalink
Build fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
brunns authored and KevinEtchells committed May 23, 2024
1 parent 7f4b53b commit 6e5777f
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 193 deletions.
117 changes: 60 additions & 57 deletions django_app/poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion django_app/tests_playwright/_settings.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BASE_URL = "http://localhost:8090"
BASE_URL = "http://localhost:8090"
19 changes: 10 additions & 9 deletions django_app/tests_playwright/_signin.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import logging
import os
import subprocess
from playwright.sync_api import Page, expect
from dotenv import load_dotenv
from pathlib import Path
from _settings import BASE_URL

from _settings import BASE_URL
from dotenv import load_dotenv
from playwright.sync_api import Page, expect

logger = logging.getLogger(__name__)
ROOT = Path(__file__).parents[1]
load_dotenv(dotenv_path=ROOT / ".env", override=True)


def sign_in(page: Page):

email_address = os.environ["USER_EMAIL"]

if not email_address:
raise Exception("USER_EMAIL not set in your .env - this must be set to the email address you use for signing in.")
message = "USER_EMAIL not set in your .env - this must be set to the email address you use for signing in."
raise ValueError(message)

# Sign in page
page.goto(f"{BASE_URL}/sign-in/")
Expand All @@ -24,12 +26,11 @@ def sign_in(page: Page):
page.get_by_text("Continue").click()

# Get magic link
current_script_path = os.path.abspath(__file__)
django_dir = os.path.dirname(os.path.dirname(current_script_path))
django_dir = Path(__file__).parents[2]
command = ["poetry", "run", "python", "manage.py", "show_magiclink_url", email_address]
result = subprocess.run(command, capture_output=True, text=True, cwd=django_dir)
result = subprocess.run(command, capture_output=True, text=True, cwd=django_dir) # noqa: S603
magic_link = result.stdout.strip()

# Complete sign-in and verify
page.goto(f"{BASE_URL}{magic_link}")
page.get_by_role("button").click()
Expand Down
46 changes: 29 additions & 17 deletions django_app/tests_playwright/test_accessibility.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
from playwright.sync_api import Page, expect
from axe_playwright_python.sync_playwright import Axe
import logging

from _settings import BASE_URL
from _signin import sign_in
from axe_playwright_python.sync_playwright import Axe
from playwright.sync_api import Page, expect

URLS = [
"/",
"/sign-in",
"/privacy-notice",
"/accessibility-statement",
"/support",
"/documents",
"/upload",
"/chats"
]
logger = logging.getLogger(__name__)
URLS = ["/", "/sign-in", "/privacy-notice", "/accessibility-statement", "/support", "/documents", "/upload", "/chats"]

# All available rules/categories are here: https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md
# Can't include all as gov.uk design system violates the "region" rule
AXE_OPTIONS = {"runOnly": {"type": "tag", "values": ["wcag2a", "wcag2aa", "wcag21aa", "wcag22aa", "cat.aria", "cat.name-role-value", "cat.structure", "cat.semantics", "cat.text-alternatives", "cat.forms", "cat.sensory-and-visual-cues", "cat.tables", "cat.time-and-media"]}}
AXE_OPTIONS = {
"runOnly": {
"type": "tag",
"values": [
"wcag2a",
"wcag2aa",
"wcag21aa",
"wcag22aa",
"cat.aria",
"cat.name-role-value",
"cat.structure",
"cat.semantics",
"cat.text-alternatives",
"cat.forms",
"cat.sensory-and-visual-cues",
"cat.tables",
"cat.time-and-media",
],
}
}

axe = Axe()

def test_violations(page: Page):

def test_violations(page: Page):
sign_in(page)

for url in URLS:

page.goto(f"{BASE_URL}{url}")
results = axe.run(page, context=None, options=AXE_OPTIONS)
print(f"\nURL: {url}")
print(results.generate_report())
logger.debug("\nURL: %s", url)
logger.info(results.generate_report())

if results.violations_count > 0:
# Because Python Playwright assertions can't take normal expressions, booleans etc.
Expand Down
3 changes: 2 additions & 1 deletion django_app/tests_playwright/test_demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from playwright.sync_api import Page, expect
from _settings import BASE_URL
from playwright.sync_api import Page, expect


def test_has_title(page: Page):
page.goto(BASE_URL)
Expand Down
Loading

0 comments on commit 6e5777f

Please sign in to comment.