Fetching has two filters, and a company now overrides each on its own.
All countries (companies.all_countries) is the old All roles tag: its big
boards are read with the agents' wide reach. All roles (companies.all_roles,
new meaning) drops the agents' fetch terms and any later role filter.
- Migration 24 copies the old tag to all_countries and keeps all_roles for
those companies, and moves a board's {"terms": false} to its company.
- The runner no longer reads {"terms": false}; the plan leaves the terms out
for a company set to All roles.
- POST /api/companies/{key}/all-countries and /all-roles, each queueing a
pull when turned on; CompanyOut carries both.
- Two toggles replace All on the Companies row, the reader and the Roles
strip; the reach line states countries and role types in plain words;
the filter select gets both options.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
155 lines
6.8 KiB
Python
155 lines
6.8 KiB
Python
"""A board's own reach on the Companies list, and the readers' declarations
|
|
on the Sources page, through the JSON API. No network."""
|
|
|
|
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.models import Gate
|
|
from app.storage import Store
|
|
|
|
|
|
@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
|
|
|
|
|
|
@pytest.fixture
|
|
def bosch(store: Store) -> int:
|
|
"""A big SmartRecruiters board and an agent that wants Denmark or remote."""
|
|
store.save_agent("Wolf", gates=[Gate(field="country", values=["DK"], mode="any"),
|
|
Gate(field="remote", values=["remote"], mode="any")])
|
|
sub = store.add_subscription("ats", "smartrecruiters:BoschGroup", label="Bosch",
|
|
company="Bosch", board="smartrecruiters",
|
|
params={"note": "kept"})
|
|
store.add_company("Bosch")
|
|
store.state["ats:size:smartrecruiters:BoschGroup"] = "4830"
|
|
return sub.id
|
|
|
|
|
|
def _row(client: TestClient) -> dict[str, object]:
|
|
return next(c for c in client.get("/api/companies").json() if c["key"] == "bosch")
|
|
|
|
|
|
def test_a_company_row_says_what_its_board_is_asked_for(client: TestClient, bosch: int) -> None:
|
|
row = _row(client)
|
|
# SmartRecruiters cannot ask for remote, so only the country is asked.
|
|
assert (row["reach"], row["reach_params"]) == ("follows agents: DK · all roles", {})
|
|
|
|
|
|
def test_a_boards_own_reach_is_kept_in_its_params_and_wins(
|
|
client: TestClient, store: Store, bosch: int) -> None:
|
|
res = client.post(f"/api/sources/{bosch}/reach",
|
|
json={"mode": "own", "countries": ["de", "se"], "remote": True})
|
|
assert res.status_code == 200, res.text
|
|
assert res.json()["reach"] == "set here: DE, SE · all roles"
|
|
sub = store.subscription(bosch)
|
|
assert sub is not None
|
|
assert sub.params == {"note": "kept", "countries": ["DE", "SE"], "remote": True}
|
|
assert _row(client)["reach_params"] == {"countries": ["DE", "SE"], "remote": True}
|
|
|
|
res = client.post(f"/api/sources/{bosch}/reach", json={"mode": "agents"})
|
|
assert res.json()["reach"] == "follows agents: DK · all roles"
|
|
assert store.subscription(bosch).params == {"note": "kept"} # type: ignore[union-attr]
|
|
|
|
|
|
@pytest.mark.parametrize("body, status", [
|
|
({"mode": "own"}, 422),
|
|
({"mode": "own", "countries": ["XX"]}, 422),
|
|
({"mode": "own", "countries": ["EU"]}, 422),
|
|
({"mode": "nowhere"}, 422),
|
|
({"mode": "all"}, 422), # every role is the company's tag now
|
|
])
|
|
def test_a_reach_that_names_nothing_is_refused(
|
|
client: TestClient, bosch: int, body: dict[str, object], status: int) -> None:
|
|
assert client.post(f"/api/sources/{bosch}/reach", json=body).status_code == status
|
|
|
|
|
|
def test_a_search_or_an_unknown_board_has_no_reach(client: TestClient, store: Store) -> None:
|
|
search = store.add_subscription("search", "jobindex:x", label="X", board="jobindex",
|
|
params={"q": "python"})
|
|
assert client.post(f"/api/sources/{search.id}/reach",
|
|
json={"mode": "agents"}).status_code == 404
|
|
assert client.post("/api/sources/999/reach", json={"mode": "agents"}).status_code == 404
|
|
|
|
|
|
#: Every state a job may be in, for a "was one queued at all" check that does
|
|
#: not race a background worker draining it.
|
|
_ANY_STATE = ("queued", "running", "done", "failed", "cancelled")
|
|
|
|
|
|
def test_all_countries_reads_the_wide_reach_and_on_queues_a_pull(
|
|
client: TestClient, app: FastAPI, store: Store, bosch: int) -> None:
|
|
queue = app.state.queue
|
|
res = client.post("/api/companies/bosch/all-countries", json={"on": True})
|
|
assert res.status_code == 200, res.text
|
|
assert (res.json()["all_countries"], res.json()["all_roles"]) == (1, 0)
|
|
# On reopens roles, so it queues a pull as switching a board on does.
|
|
assert queue.jobs.last("pull", states=_ANY_STATE) is not None
|
|
row = _row(client)
|
|
# Wolf requires no place, so the wide reach is everywhere.
|
|
assert (row["all_countries"], row["all_roles"], row["reach"]) == (
|
|
True, False, "all countries (everywhere): read whole")
|
|
# A board's own countries win over it.
|
|
client.post(f"/api/sources/{bosch}/reach", json={"mode": "own", "countries": ["DE"]})
|
|
assert _row(client)["reach"] == "set here: DE · all roles"
|
|
|
|
|
|
def test_all_roles_is_its_own_switch_and_on_queues_a_pull(
|
|
client: TestClient, app: FastAPI, store: Store, bosch: int) -> None:
|
|
res = client.post("/api/companies/bosch/all-roles", json={"on": True})
|
|
assert res.status_code == 200, res.text
|
|
assert (res.json()["all_countries"], res.json()["all_roles"]) == (0, 1)
|
|
assert app.state.queue.jobs.last("pull", states=_ANY_STATE) is not None
|
|
row = _row(client)
|
|
# The narrow reach takes no terms, so on its own it changes nothing today.
|
|
assert (row["all_countries"], row["all_roles"], row["reach"]) == (
|
|
False, True, "follows agents: DK · all roles")
|
|
|
|
|
|
@pytest.mark.parametrize("path, setter", [("all-countries", "set_all_countries"),
|
|
("all-roles", "set_all_roles")])
|
|
def test_turning_an_override_off_queues_nothing(
|
|
client: TestClient, app: FastAPI, store: Store, bosch: int, path: str,
|
|
setter: str) -> None:
|
|
getattr(store, setter)("bosch", True)
|
|
res = client.post(f"/api/companies/bosch/{path}", json={"on": False})
|
|
assert res.status_code == 200
|
|
assert (res.json()["all_countries"], res.json()["all_roles"]) == (0, 0)
|
|
assert app.state.queue.jobs.last("pull", states=_ANY_STATE) is None
|
|
assert _row(client)["reach"] == "follows agents: DK · all roles"
|
|
assert client.post(f"/api/companies/nobody/{path}", json={"on": True}).status_code == 404
|
|
|
|
|
|
def test_the_readers_are_listed_with_what_they_declare(client: TestClient) -> None:
|
|
found = {r["name"]: r for r in client.get("/api/readers").json()}
|
|
assert found["workday"] == {
|
|
"name": "workday", "label": "Workday", "scope": "board", "listing": "paged",
|
|
"text": "detail", "filters": {"country": "ids", "remote": "ids", "query": "one"},
|
|
"places": "many",
|
|
"robots": found["workday"]["robots"]}
|
|
assert found["workday"]["robots"].startswith("read:")
|
|
assert found["greenhouse"]["filters"] == {}
|
|
scopes = [r["scope"] for r in client.get("/api/readers").json()]
|
|
assert scopes == sorted(scopes) # boards first, then the searches
|
|
assert "search" in scopes
|