113 lines
4.4 KiB
Python
113 lines
4.4 KiB
Python
"""The Roles page's part of the ranking flow (documentation/ADR Fetch prep and score.md, "5 Feed"):
|
|
the note that the feed keeps to the agent's fetch gate, the saved filters in
|
|
the rail and the routes they call, as `static/roles.js` uses them. A temp
|
|
database and FastAPI's TestClient; no browser."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Iterator
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.config import Config, ServerConfig
|
|
from app.main import create_app
|
|
from app.storage import Store
|
|
|
|
STATIC = Path(__file__).resolve().parent.parent / "app" / "static"
|
|
|
|
|
|
@pytest.fixture
|
|
def app(tmp_path: Path) -> FastAPI:
|
|
return create_app(Config(server=ServerConfig(host="127.0.0.1", port=0),
|
|
database=tmp_path / "roledesk.db"))
|
|
|
|
|
|
@pytest.fixture
|
|
def store(app: FastAPI) -> Store:
|
|
return app.state.store
|
|
|
|
|
|
@pytest.fixture
|
|
def client(app: FastAPI) -> Iterator[TestClient]:
|
|
with TestClient(app) as c:
|
|
yield c
|
|
|
|
|
|
def test_the_rail_says_the_feed_keeps_to_the_fetch_gate_and_offers_saved_filters(
|
|
client: TestClient) -> None:
|
|
page = client.get("/").text
|
|
assert 'id="agent-gate"' in page
|
|
for name in ("saved", "saved-list", "save-open", "save-form", "save-name", "saved-note"):
|
|
assert f'id="{name}"' in page
|
|
script = (STATIC / "roles.js").read_text()
|
|
assert "Already filtered by this agent's fetch gate" in script
|
|
# The name is asked in the page, never by a browser prompt.
|
|
assert "prompt(" not in script
|
|
|
|
|
|
def test_no_text_says_a_favourite_skips_the_places() -> None:
|
|
script = (STATIC / "roles.js").read_text()
|
|
for stale in ("outside your places", "Kept out of the ranking", "required gates allow"):
|
|
assert stale not in script
|
|
|
|
|
|
def test_a_saved_filter_round_trips_the_query_roles_js_writes(
|
|
client: TestClient, store: Store) -> None:
|
|
agent = store.save_agent("Wolf")
|
|
query = "q=engineer&remote=remote&places=country%3ADK&gated=true&sort=time"
|
|
|
|
made = client.post(f"/api/agents/{agent.id}/filters",
|
|
json={"name": "Remote engineers", "query": query})
|
|
assert made.status_code == 201
|
|
assert made.json()["query"] == query
|
|
|
|
listed = client.get(f"/api/agents/{agent.id}/filters").json()
|
|
assert [(f["name"], f["query"]) for f in listed] == [("Remote engineers", query)]
|
|
|
|
# Case does not make a second name; the page says the 409 under the field.
|
|
twice = client.post(f"/api/agents/{agent.id}/filters",
|
|
json={"name": "remote ENGINEERS", "query": ""})
|
|
assert twice.status_code == 409 and twice.json()["detail"]
|
|
assert client.post(f"/api/agents/{agent.id}/filters",
|
|
json={"name": " ", "query": ""}).status_code == 422
|
|
assert client.get("/api/agents/999/filters").status_code == 404
|
|
|
|
gone = client.delete(f"/api/filters/{made.json()['id']}")
|
|
assert gone.status_code == 204
|
|
# A second delete, from a page that had not heard of the first, is a 404
|
|
# the page treats as done.
|
|
assert client.delete(f"/api/filters/{made.json()['id']}").status_code == 404
|
|
assert client.get(f"/api/agents/{agent.id}/filters").json() == []
|
|
|
|
|
|
def test_the_feed_orders_carry_the_adrs_names() -> None:
|
|
script = (STATIC / "roles.js").read_text()
|
|
assert "What I\\u2019m looking for" in script and '"What fits me"' in script
|
|
assert 'time: "Newest"' in script
|
|
assert "Agent match" not in script
|
|
|
|
|
|
def test_the_rail_has_no_show_hidden_companies_and_the_feed_never_asks_for_them(
|
|
client: TestClient) -> None:
|
|
page = client.get("/").text
|
|
assert "f-show-muted" not in page and "Show hidden companies" not in page
|
|
script = (STATIC / "roles.js").read_text()
|
|
assert "show_muted" not in script and "showMuted" not in script
|
|
|
|
|
|
def test_the_reader_shows_the_judges_numbers_of_ten() -> None:
|
|
script = (STATIC / "roles.js").read_text()
|
|
assert "skills ${j.skills}/10" in script and "experience ${j.experience}/10" in script
|
|
assert "career ${j.career}/10" in script
|
|
assert "of 100" in script # the CV match itself stays on 0 to 100
|
|
|
|
|
|
def test_every_page_says_all_locations() -> None:
|
|
for path in STATIC.glob("*.js"):
|
|
assert "All countries" not in path.read_text(), path.name
|
|
for path in (STATIC.parent / "templates").rglob("*.html"):
|
|
assert "All countries" not in path.read_text(), path.name
|