- customers-moduuli Clean Architecture -kerroksin: asiakas (yritys/kuluttaja), Y-tunnuksen tarkiste ja yksilöllisyys, yhteyshenkilöt, laskutusyksiköt (verkkolaskuosoite vaatii välittäjätunnuksen) - henkilötunnus salattuna (Fernet) ja HMAC-tiiviste päällekkäisyyksiin; pääkäyttäjä ja johto näkevät ja poistavat, muut näkevät peitettynä - sisäinen asiakas data-migraatiolla, ei poistettavissa - yleinen poistonesto käänteisten relaatioiden perusteella (tulevat PROTECT-viiteavaimet estävät poiston automaattisesti) - asiakkaan sivu: lisäys ja muokkaus dialogissa HTMX:llä, fokuksen hallinta ja ruudunlukijailmoitukset; HTMX näyttää nyt 422-validointivirheet - testit: domain, application, integraatio ja selaintestit (axe); yhteiset fixturet apps/conftest.py:hin, FakeUnitOfWork shared-moduuliin - import-linter: moduulien riippumattomuussäännöt - dokumentit päivitetty Co-Authored-By: Claude Opus 5.5 <[email protected]>
87 lines
3.3 KiB
Python
87 lines
3.3 KiB
Python
from collections.abc import Callable
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
from tests.browser.conftest import ALL, assert_accessible, no_horizontal_scroll
|
|
|
|
|
|
@pytest.mark.parametrize("themed_page", ALL, indirect=True, ids=lambda p: f"{p[0]}-{p[1]}")
|
|
def test_public_pages(themed_page: Any, live_server: Any, transactional_db: Any) -> None:
|
|
for path in (
|
|
"/login/",
|
|
"/login/?access=ended",
|
|
"/password/forgot/",
|
|
"/password/set/setup/x/y/",
|
|
):
|
|
themed_page.goto(f"{live_server.url}{path}")
|
|
assert_accessible(themed_page)
|
|
assert no_horizontal_scroll(themed_page), path
|
|
|
|
|
|
@pytest.mark.parametrize("themed_page", ALL, indirect=True, ids=lambda p: f"{p[0]}-{p[1]}")
|
|
def test_user_management_pages(
|
|
themed_page: Any, live_server: Any, admin_user: Any, login: Callable[[Any, str], None]
|
|
) -> None:
|
|
login(themed_page, admin_user.email)
|
|
for path in ("/", "/users/", "/users/new/", f"/users/{admin_user.pk}/edit/"):
|
|
themed_page.goto(f"{live_server.url}{path}")
|
|
assert_accessible(themed_page)
|
|
assert no_horizontal_scroll(themed_page), path
|
|
|
|
|
|
def test_form_errors_are_accessible(
|
|
page: Any, live_server: Any, admin_user: Any, login: Callable[[Any, str], None]
|
|
) -> None:
|
|
login(page, admin_user.email)
|
|
page.goto(f"{live_server.url}/users/new/")
|
|
page.select_option("#id_role", "intern")
|
|
page.click("main button[type=submit]")
|
|
end_date = page.locator("#id_name")
|
|
assert end_date.get_attribute("aria-invalid") == "true"
|
|
assert "id_name_error" in (end_date.get_attribute("aria-describedby") or "")
|
|
assert_accessible(page)
|
|
|
|
|
|
def test_keyboard_password_link_flow(
|
|
page: Any, live_server: Any, admin_user: Any, login: Callable[[Any, str], None]
|
|
) -> None:
|
|
"""Create a password link with the keyboard only and copy it."""
|
|
page.context.grant_permissions(["clipboard-read", "clipboard-write"])
|
|
login(page, admin_user.email)
|
|
page.goto(f"{live_server.url}/users/{admin_user.pk}/edit/")
|
|
page.get_by_role("button", name="Luo salasanalinkki").focus()
|
|
page.keyboard.press("Enter")
|
|
dialog = page.locator("dialog#confirm-password-link")
|
|
assert dialog.evaluate("d => d.open")
|
|
page.get_by_role("button", name="Luo linkki").focus()
|
|
page.keyboard.press("Enter")
|
|
link_box = page.locator("#password-link-box")
|
|
link_box.wait_for()
|
|
assert not dialog.evaluate("d => d.open")
|
|
page.wait_for_timeout(500) # let the modal close animation finish before axe
|
|
page.get_by_role("button", name="Kopioi").focus()
|
|
page.keyboard.press("Enter")
|
|
page.wait_for_function(
|
|
"document.getElementById('live-region').textContent.includes('kopioitu')"
|
|
)
|
|
copied = page.evaluate("navigator.clipboard.readText()")
|
|
assert "/password/set/setup/" in copied
|
|
assert_accessible(page)
|
|
|
|
|
|
def test_htmx_search_updates_table(
|
|
page: Any, live_server: Any, admin_user: Any, login: Callable[[Any, str], None]
|
|
) -> None:
|
|
from apps.users.infrastructure.orm import User
|
|
|
|
User.objects.create_user(email="[email protected]", name="Eeva Esimerkki")
|
|
login(page, admin_user.email)
|
|
page.goto(f"{live_server.url}/users/")
|
|
page.fill("#id_q", "eeva")
|
|
page.wait_for_url("**/users/?q=eeva**")
|
|
rows = page.locator("#user-table tbody tr")
|
|
rows.first.wait_for()
|
|
assert rows.count() == 1
|
|
assert "Eeva Esimerkki" in rows.first.inner_text()
|