Allowing unauthenticated users to see scopes

This commit is contained in:
Ian Roddis committed 2026-08-18 13:44:55 -03:00
1 parent 2ce4f91e4f
commit 3253d8e858
8 files changed
+136 -27

No files matched your search

+49 -4
View File
@@ -341,11 +341,56 @@ async def test_scopes_page_forbidden_without_permission(client, seeded, make_use
@pytest.mark.asyncio
async def test_scopes_page_redirects_when_anonymous(client):
async def test_scopes_page_renders_for_anonymous(client, db_sessionmaker):
async with db_sessionmaker() as db:
await _seed_guide_data(db)
resp = await client.get("/scopes")
assert resp.status_code == 302
# Deep link is preserved so the user lands back here after logging in.
assert resp.headers["location"] == "/login?next=%2Fscopes"
assert resp.status_code == 200
body = resp.text
assert "Alpha 3-18x50" in body
assert "fit-badge-exact" in body
# Possible fits (e.g. the ARD) are hidden entirely from anonymous visitors.
assert "ARD 50mm" not in body
assert "fit-badge-possible" not in body
@pytest.mark.asyncio
async def test_scopes_page_hides_write_controls_for_anonymous(client, db_sessionmaker):
async with db_sessionmaker() as db:
await _seed_guide_data(db)
resp = await client.get("/scopes")
assert resp.status_code == 200
assert 'name="scope_ids"' not in resp.text
assert "delete-selected-scopes-btn" not in resp.text
@pytest.mark.asyncio
async def test_scopes_filter_endpoint_works_for_anonymous(client, db_sessionmaker):
async with db_sessionmaker() as db:
await _seed_guide_data(db)
resp = await client.get("/scopes/filter", params={"description": "Alpha"})
assert resp.status_code == 200
assert "Alpha 3-18x50" in resp.text
assert "Zeta 1-6x24" not in resp.text
@pytest.mark.asyncio
async def test_build_only_exact_drops_possible_fits(db_sessionmaker):
async with db_sessionmaker() as db:
ids = await _seed_guide_data(db)
guide = await scope_guide.build(db, only_exact=True)
cover_id, ard_id = ids["cover"].id, ids["ard"].id
rows = {r["scope"].description: r for r in guide["rows"]}
s1 = rows["Alpha 3-18x50"]
assert [(e["part"].description, e["label"]) for e in s1["cells"][cover_id]] == [
("Flip cover 50mm", "exact")
]
assert ard_id not in s1["cells"] # the ARD fit was only "possible"
s2 = rows["Zeta 1-6x24"]
assert cover_id not in s2["cells"] # S2's flip-cover fit was only "possible"
@pytest.mark.asyncio