Skip to content

Commit 39ae11c

Browse files
fix: address PR review nits for frontend test suite
Rename the misnamed CSRF browser test, drop the duplicate jinja context assertion from test_templates, document the autouse org fixture, and use None with explicit org_id override in GET page cases.
1 parent 9d66c31 commit 39ae11c

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

tests/browser/test_browser_csrf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_htmx_login_with_valid_csrf_succeeds(browser, live_server_csrf: str):
7272
context.close()
7373

7474

75-
def test_org_htmx_action_requires_csrf_header(browser, live_server_csrf: str):
75+
def test_forgot_password_without_csrf_shows_error_toast(browser, live_server_csrf: str):
7676
context = browser.new_context(viewport={"width": 1280, "height": 720})
7777
page = context.new_page()
7878
page.goto(f"{live_server_csrf}/account/forgot_password")

tests/test_get_pages_jinja_integration.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ def _url(name: str, **path_params) -> str:
2222
class GetPageCase:
2323
id: str
2424
client_fixture: str
25-
path_factory: Callable[[], str]
25+
path_factory: Callable[[], str | None]
2626
marker: str | None = None
2727
jinja_route: str | None = None
2828
expected_status: int = 200
2929

3030

3131
GET_PAGE_CASES = [
32-
GetPageCase("home", "unauth_client", lambda: _url("read_home"), jinja_route="read_home"),
32+
GetPageCase(
33+
"home", "unauth_client", lambda: _url("read_home"), jinja_route="read_home"
34+
),
3335
GetPageCase(
3436
"login", "unauth_client", lambda: _url("read_login"), jinja_route="read_login"
3537
),
@@ -68,14 +70,14 @@ class GetPageCase:
6870
GetPageCase(
6971
"organization_owner",
7072
"auth_client_owner",
71-
lambda: _url("read_organization", org_id=0),
73+
lambda: None,
7274
marker="Create Role",
7375
jinja_route="read_organization",
7476
),
7577
GetPageCase(
7678
"organization_member",
7779
"auth_client_member",
78-
lambda: _url("read_organization", org_id=0),
80+
lambda: None,
7981
marker="Members",
8082
jinja_route="read_organization",
8183
),
@@ -99,7 +101,8 @@ def _setup_org_owner(
99101
test_organization,
100102
org_owner,
101103
):
102-
"""Ensure org-scoped clients have a membership relationship loaded."""
104+
# No setup body: autouse only so test_organization and org_owner run before
105+
# org-scoped client fixtures (auth_client_owner, auth_client_member).
103106
del request, test_organization, org_owner
104107

105108
def test_static_context_analysis_passes(self, missing_context_variables):
@@ -139,7 +142,7 @@ def test_get_page_renders(
139142
assert not missing_context_variables
140143
client = request.getfixturevalue(case.client_fixture)
141144
path = case.path_factory()
142-
if "organization" in case.id:
145+
if path is None:
143146
assert test_organization.id is not None
144147
path = _url("read_organization", org_id=test_organization.id)
145148
response = client.get(path)
@@ -215,7 +218,7 @@ class TestGetPagesRequireAuth:
215218
[
216219
("unauth_client", lambda: _url("read_dashboard")),
217220
("unauth_client", lambda: _url("read_profile")),
218-
("unauth_client", lambda: _url("read_organization", org_id=1)),
221+
("unauth_client", lambda: None),
219222
],
220223
ids=["dashboard", "profile", "organization"],
221224
)
@@ -228,7 +231,7 @@ def test_unauthenticated_redirects_to_login(
228231
):
229232
client = request.getfixturevalue(client_fixture)
230233
path = path_factory()
231-
if "organization" in request.node.callspec.id:
234+
if path is None:
232235
assert test_organization.id is not None
233236
path = _url("read_organization", org_id=test_organization.id)
234237
response = client.get(path)

tests/test_templates.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ def test_no_hardcoded_routes(hardcoded_routes):
1414
assert not hardcoded_routes, hardcoded_routes
1515

1616

17-
def test_no_missing_context_variables(missing_context_variables):
18-
"""Test that routes pass all required variables to their templates."""
19-
assert not missing_context_variables, missing_context_variables
20-
21-
2217
def test_valid_endpoints(validate_endpoints):
2318
"""Test that url_for() calls in templates reference valid FastAPI endpoints."""
2419
from main import app

0 commit comments

Comments
 (0)