Filter the feed by company keys, place tokens and seniority, and suggest companies and places
Migration 17 adds roles.place_fold and fills seniority from the title where extract has not read the role. Every connection registers place_match, so the Place filter and the place gate match whole folded words: Lund no longer finds Billund. GET /api/roles takes company_keys, places, seniority, seniority_unknown and pay_unknown; new routes suggest companies and places, label place tokens and count the seniority and pay facets. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
4b9403a0b9
commit
a91b4e99e0
6 files changed
+724
-60
No files matched your search
+107
-1
@@ -91,6 +91,111 @@ def test_list_roles_filters_by_query_place_and_function(
|
||||
assert [r["uid"] for r in res.json()["items"]] == [uid["3"]]
|
||||
|
||||
|
||||
def test_list_roles_filters_by_company_keys_places_and_seniority(
|
||||
client: TestClient, store: Store) -> None:
|
||||
for sid, company, place, title in (
|
||||
("kbh", "Acme", "København K", "Senior Engineer"),
|
||||
("malmo", "Acme", "Malmö", "Engineer"),
|
||||
("billund", "Other", "Billund, Denmark", "Junior Engineer"),
|
||||
("berlin", "Other", "Berlin", "Senior Engineer")):
|
||||
item = posting(sid, company=company, place=place)
|
||||
item.title = title
|
||||
store.upsert_role(item)
|
||||
uid = {r.source_id: r.uid for r in store.roles()}
|
||||
|
||||
def shown(**params: Any) -> set[str]:
|
||||
res = client.get("/api/roles", params=params)
|
||||
assert res.status_code == 200, res.text
|
||||
assert res.json()["total"] == len(res.json()["items"])
|
||||
return {sid for sid, u in uid.items() if u in {r["uid"] for r in res.json()["items"]}}
|
||||
|
||||
assert shown(company_keys=["acme"]) == {"kbh", "malmo"}
|
||||
assert shown(company_keys=["acme", "other"]) == set(uid)
|
||||
assert shown(places=["country:DK"]) == {"kbh", "billund"}
|
||||
assert shown(places=["country:DK", "region:skane"]) == {"kbh", "billund", "malmo"}
|
||||
assert shown(places=["place:kobenhavn"]) == {"kbh"}
|
||||
assert shown(places=["Lund"]) == set() # not Billund
|
||||
assert shown(seniority=["senior"]) == {"kbh", "berlin", "malmo"}
|
||||
assert shown(seniority=["senior"], seniority_unknown="false") == {"kbh", "berlin"}
|
||||
assert shown(seniority=["senior", "junior"], seniority_unknown="false",
|
||||
company_keys=["other"]) == {"billund", "berlin"}
|
||||
|
||||
res = client.get("/api/roles", params={"places": ["region:atlantis"]})
|
||||
assert res.status_code == 422 and "region:atlantis" in res.json()["detail"]
|
||||
res = client.get("/api/roles", params={"seniority": ["boss"]})
|
||||
assert res.status_code == 422 and "boss" in res.json()["detail"]
|
||||
|
||||
|
||||
def test_role_facets_count_each_facet_under_the_other_filters(
|
||||
client: TestClient, store: Store) -> None:
|
||||
for sid, title, raw in (("a", "Senior Engineer", {"salary_min": 70000}),
|
||||
("b", "Senior Engineer", {}),
|
||||
("c", "Engineer", {"salary_text": "EUR 50 per hour"})):
|
||||
item = posting(sid, **raw)
|
||||
item.title = title
|
||||
store.upsert_role(item)
|
||||
|
||||
res = client.get("/api/roles/facets",
|
||||
params={"seniority": ["senior"], "seniority_unknown": "false",
|
||||
"pay": "stated"})
|
||||
assert res.status_code == 200
|
||||
body = res.json()
|
||||
levels = {f["value"]: f["count"] for f in body["seniority"]}
|
||||
assert (levels["senior"], levels[""], levels["junior"]) == (1, 1, 0) # a and c pay
|
||||
assert body["pay"] == [{"value": "normalised", "count": 1}, # a and b are senior
|
||||
{"value": "stated", "count": 0}, {"value": "", "count": 1}]
|
||||
assert client.get("/api/roles/facets", params={"places": ["country:ZZ"]}).status_code == 422
|
||||
|
||||
|
||||
def test_suggest_companies_folds_the_name_and_leaves_out_the_hidden(
|
||||
client: TestClient, store: Store) -> None:
|
||||
for sid, company in (("1", "Ørsted"), ("2", "Ørsted"), ("3", "Data Minds"),
|
||||
("4", "Big Data Corp"), ("5", "Big Data Corp"), ("6", "Big Data Corp"),
|
||||
("7", "Metadata Ltd"), ("8", "Hidden Data")):
|
||||
store.upsert_role(posting(sid, company=company))
|
||||
agent = store.save_agent("A")
|
||||
store.set_affinity(agent.id, "hidden-data", -1)
|
||||
store.set_affinity(agent.id, "ørsted", 2)
|
||||
|
||||
def suggest(q: str, **params: Any) -> list[dict[str, Any]]:
|
||||
res = client.get("/api/suggest/companies", params={"q": q, **params})
|
||||
assert res.status_code == 200
|
||||
return res.json()
|
||||
|
||||
assert suggest("orsted") == [{"key": "ørsted", "name": "Ørsted", "count": 2,
|
||||
"affinity": 2}]
|
||||
# A word prefix, not a substring: Metadata is not found; by open roles.
|
||||
assert [c["name"] for c in suggest("data")] == ["Big Data Corp", "Data Minds"]
|
||||
assert [c["name"] for c in suggest("big da")] == ["Big Data Corp"]
|
||||
assert [c["name"] for c in suggest("data", limit=1)] == ["Big Data Corp"]
|
||||
assert suggest("") == []
|
||||
# Another agent hid nothing.
|
||||
other = store.save_agent("B")
|
||||
assert "Hidden Data" in [c["name"] for c in suggest("data", agent=other.id)]
|
||||
|
||||
|
||||
def test_suggest_places_and_read_labels_back(client: TestClient, store: Store) -> None:
|
||||
for sid, place in (("1", "Malmö"), ("2", "Malmö"), ("3", "Lund"),
|
||||
("4", "København K"), ("5", "Kolding")):
|
||||
store.upsert_role(posting(sid, place=place))
|
||||
|
||||
res = client.get("/api/suggest/places", params={"q": "ska"})
|
||||
assert res.status_code == 200
|
||||
assert res.json()[0] == {"token": "region:skane", "label": "Skåne", "kind": "region",
|
||||
"count": 3}
|
||||
tokens = [s["token"] for s in client.get("/api/suggest/places",
|
||||
params={"q": "kob"}).json()]
|
||||
assert "place:kobenhavn" in tokens
|
||||
assert client.get("/api/suggest/places", params={"q": ""}).json() == []
|
||||
|
||||
res = client.get("/api/places/labels",
|
||||
params={"tokens": ["country:DK", "region:skane", "place:malmo",
|
||||
"region:atlantis"]})
|
||||
assert res.json() == [{"token": "country:DK", "label": "Denmark"},
|
||||
{"token": "region:skane", "label": "Skåne"},
|
||||
{"token": "place:malmo", "label": "Malmö"}]
|
||||
|
||||
|
||||
def test_list_roles_exposes_and_filters_by_pay(client: TestClient, store: Store) -> None:
|
||||
"""`salary_text` and `salary_state` (app/models.py) are on every role the
|
||||
API serves, and `pay` (`Store.PAY`) filters the feed by it, in SQL before
|
||||
@@ -1052,13 +1157,14 @@ def test_list_roles_serves_the_row_projection_and_not_the_big_columns(
|
||||
row = client.get("/api/roles").json()["items"][0]
|
||||
assert set(row) == {
|
||||
"uid", "company_key", "company", "title", "place", "country", "remote", "function",
|
||||
"salary_min", "salary_max", "currency", "salary_text", "salary_state",
|
||||
"seniority", "salary_min", "salary_max", "currency", "salary_text", "salary_state",
|
||||
"original_url", "posted_at", "score", "gated_reason", "prompt", "vote",
|
||||
"voted_at", "read_at", "tags", "excerpt",
|
||||
}
|
||||
assert row["uid"] == uid
|
||||
assert row["company"] == "Acme" and row["place"] == "Berlin, Germany"
|
||||
assert row["remote"] == "hybrid" and row["function"] == "engineering"
|
||||
assert row["seniority"] == "senior" # "Senior Backend Engineer"
|
||||
assert len(row["excerpt"]) <= 200
|
||||
assert row["excerpt"] == models_excerpt(long_description)
|
||||
|
||||
|
||||
Reference in new issue
Block a user