Merge branch 'main' into wp0-hosts
This commit is contained in:
commit
a7bb6c20ae
17 files changed
+1618
-313
No files matched your search
+245
-4
@@ -83,6 +83,16 @@ def test_set_board_attaches_a_board_to_a_row_without_one(store: Store, boards: B
|
||||
"ashby", "acme", "acme.example", "met them", "https://acme.example/careers")
|
||||
|
||||
|
||||
def test_set_board_clears_the_reason_a_company_was_read_by_hand(
|
||||
store: Store, boards: Boards) -> None:
|
||||
store.add_company("Acme", careers_url="https://acme.example/careers", hand_reason="unread")
|
||||
sources.set_board(store, "acme", "ashby:acme")
|
||||
acme = store.company("acme")
|
||||
assert acme is not None
|
||||
# The link a person set stays; the reason goes with the board's arrival.
|
||||
assert (acme.hand_reason, acme.careers_url) == ("", "https://acme.example/careers")
|
||||
|
||||
|
||||
def test_set_board_replaces_a_board_and_closes_its_open_roles(
|
||||
store: Store, boards: Boards) -> None:
|
||||
old, _, _ = sources.set_board(store, "acme", "greenhouse:acme", name="Acme")
|
||||
@@ -110,7 +120,7 @@ def test_a_board_that_does_not_answer_or_is_unknown_is_refused(
|
||||
with pytest.raises(ValueError, match="did not answer"):
|
||||
sources.set_board(store, "", "greenhouse:gone", name="Gone")
|
||||
with pytest.raises(ValueError, match="host:slug"):
|
||||
sources.set_board(store, "", "workday:gone", name="Gone")
|
||||
sources.set_board(store, "", "taleo:gone", name="Gone")
|
||||
with pytest.raises(ValueError, match="needs a name"):
|
||||
sources.set_board(store, "nobody", "greenhouse:acme")
|
||||
with pytest.raises(ValueError, match="is not the company"):
|
||||
@@ -161,20 +171,34 @@ def test_add_discovered_records_an_unreadable_host_with_its_slug(
|
||||
careers_url="https://acme.example/careers")
|
||||
assert sources.add_discovered(store, "Acme", "acme.example", found) == ("acme", 0)
|
||||
store.update_company("acme", notes="keep")
|
||||
newer = Discovery(ats="workday", ats_slug="acme-inc",
|
||||
newer = Discovery(ats="taleo", ats_slug="acme-inc",
|
||||
careers_url="https://acme.example/jobs")
|
||||
assert sources.add_discovered(store, "Acme", "acme.example", newer) == ("acme", 0)
|
||||
acme = store.company("acme")
|
||||
assert acme is not None
|
||||
# The host and slug follow what discovery found last; the link, once
|
||||
# there, is kept, since a person may have typed it.
|
||||
assert (acme.ats, acme.ats_slug, acme.careers_url, acme.notes) == (
|
||||
"workday", "acme-inc", "https://acme.example/jobs", "keep")
|
||||
"taleo", "acme-inc", "https://acme.example/careers", "keep")
|
||||
|
||||
|
||||
def test_add_discovered_fills_a_link_only_where_there_is_none(
|
||||
store: Store, boards: Boards) -> None:
|
||||
store.add_company("Acme", ats="teamtailor")
|
||||
found = Discovery(ats="taleo", ats_slug="acme", careers_url="https://acme.example/jobs")
|
||||
sources.add_discovered(store, "Acme", "acme.example", found)
|
||||
assert store.company("acme").careers_url == "https://acme.example/jobs" # type: ignore[union-attr]
|
||||
|
||||
store.update_company("acme", careers_url="https://typed.example/by-hand")
|
||||
sources.add_discovered(store, "Acme", "acme.example", found)
|
||||
assert store.company("acme").careers_url == "https://typed.example/by-hand" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_add_discovered_keeps_a_board_when_nothing_readable_was_found(
|
||||
store: Store, boards: Boards) -> None:
|
||||
sources.set_board(store, "", "greenhouse:acme", name="Acme")
|
||||
with pytest.raises(ValueError, match="nothing changed"):
|
||||
sources.add_discovered(store, "Acme", "acme.example", Discovery(ats="workday"))
|
||||
sources.add_discovered(store, "Acme", "acme.example", Discovery(ats="taleo"))
|
||||
acme = store.company("acme")
|
||||
assert acme is not None and acme.ats == "greenhouse"
|
||||
|
||||
@@ -240,6 +264,143 @@ def test_a_seed_board_that_clashes_still_lands_the_company(
|
||||
assert store.company_subscription("acme-two") is None
|
||||
|
||||
|
||||
def test_a_seed_rerun_fills_an_empty_link_and_reason_and_never_overwrites_one(
|
||||
store: Store, boards: Boards, tmp_path: Path) -> None:
|
||||
store.add_company("Bare", key="bare")
|
||||
store.add_company("Typed", key="typed", careers_url="https://typed.example/by-hand",
|
||||
hand_reason="blocked", notes="mine")
|
||||
seed = _seed(tmp_path,
|
||||
{"name": "Bare", "careers_url": "https://bare.example/jobs",
|
||||
"hand_reason": "unread"},
|
||||
{"name": "Typed", "careers_url": "https://seed.example/jobs",
|
||||
"hand_reason": "robots"},
|
||||
{"name": "Fresh", "careers_url": "https://fresh.example/jobs",
|
||||
"hand_reason": "key"})
|
||||
|
||||
result = sources.seed_companies(store, seed)
|
||||
|
||||
assert (result["added"], result["skipped"], result["problems"]) == (1, 2, [])
|
||||
got = {k: (c.careers_url, c.hand_reason, c.notes) for k in ("bare", "typed", "fresh")
|
||||
if (c := store.company(k)) is not None}
|
||||
assert got == {
|
||||
"bare": ("https://bare.example/jobs", "unread", ""),
|
||||
"typed": ("https://typed.example/by-hand", "blocked", "mine"),
|
||||
"fresh": ("https://fresh.example/jobs", "key", "")}
|
||||
# Run again, nothing moves.
|
||||
assert sources.seed_companies(store, seed)["added"] == 0
|
||||
assert store.company("bare").hand_reason == "unread" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_a_seed_reason_outside_the_vocabulary_is_a_problem_not_a_row_value(
|
||||
store: Store, boards: Boards, tmp_path: Path) -> None:
|
||||
result = sources.seed_companies(
|
||||
store, _seed(tmp_path, {"name": "Odd", "hand_reason": "lazy"}))
|
||||
assert result["problems"] == ["odd: 'lazy' is not a hand_reason; kept without it"]
|
||||
assert store.company("odd").hand_reason == "" # type: ignore[union-attr]
|
||||
|
||||
|
||||
def test_a_seed_link_reaches_a_row_whose_board_clashes(
|
||||
store: Store, boards: Boards, tmp_path: Path) -> None:
|
||||
sources.set_board(store, "acme", "greenhouse:acme", name="Acme")
|
||||
store.add_company("Twin", key="twin")
|
||||
result = sources.seed_companies(store, _seed(
|
||||
tmp_path, {"name": "Twin", "board": "greenhouse:acme",
|
||||
"careers_url": "https://twin.example/jobs"}))
|
||||
assert len(result["problems"]) == 1
|
||||
assert store.company("twin").careers_url == "https://twin.example/jobs" # type: ignore[union-attr]
|
||||
|
||||
|
||||
# ------------------------------------------------------------- by hand
|
||||
|
||||
def test_a_company_added_by_hand_has_no_board_and_a_checked_link(store: Store) -> None:
|
||||
company = sources.add_by_hand(store, "Revolut Ltd", careers_url=" https://r.example/jobs ",
|
||||
notes="login wall")
|
||||
assert (company.key, company.hand_reason, company.careers_url, company.notes) == (
|
||||
"revolut", "added", "https://r.example/jobs", "login wall")
|
||||
assert store.company_subscription("revolut") is None
|
||||
with pytest.raises(sources.Conflict, match="on the list already"):
|
||||
sources.add_by_hand(store, "REVOLUT")
|
||||
for link in ("javascript:alert(1)", "r.example/jobs", "https://", "ftp://r.example"):
|
||||
with pytest.raises(ValueError, match="http"):
|
||||
sources.add_by_hand(store, "Other", careers_url=link)
|
||||
with pytest.raises(ValueError, match="hand_reason"):
|
||||
sources.add_by_hand(store, "Other", hand_reason="lazy")
|
||||
with pytest.raises(ValueError, match="needs a name"):
|
||||
sources.add_by_hand(store, " ")
|
||||
assert [c.key for c in store.companies()] == ["revolut"]
|
||||
|
||||
|
||||
def test_edit_company_changes_what_it_is_given_and_renames_only_without_a_board(
|
||||
store: Store, boards: Boards) -> None:
|
||||
sources.add_by_hand(store, "Acme", notes="old")
|
||||
edited = sources.edit_company(store, "acme", name="Acme GmbH", hand_reason="gone")
|
||||
assert (edited.key, edited.name, edited.notes, edited.hand_reason) == (
|
||||
"acme", "Acme GmbH", "old", "gone")
|
||||
with pytest.raises(ValueError, match="needs a name"):
|
||||
sources.edit_company(store, "acme", name=" ")
|
||||
with pytest.raises(ValueError, match="not a field"):
|
||||
sources.edit_company(store, "acme", ats="lever")
|
||||
with pytest.raises(KeyError):
|
||||
sources.edit_company(store, "nobody", notes="x")
|
||||
|
||||
sources.set_board(store, "acme", "greenhouse:acme")
|
||||
with pytest.raises(sources.Conflict, match="detach"):
|
||||
sources.edit_company(store, "acme", name="Acme Labs")
|
||||
# The name it has, and any other field, are no rename.
|
||||
assert sources.edit_company(store, "acme", name="Acme GmbH", notes="new").notes == "new"
|
||||
sources.detach_board(store, "acme")
|
||||
with pytest.raises(sources.Conflict):
|
||||
sources.edit_company(store, "acme", name="Acme Labs")
|
||||
|
||||
|
||||
def test_remove_company_refuses_a_board_shown_and_open_roles(
|
||||
store: Store, boards: Boards) -> None:
|
||||
agent = store.save_agent("A")
|
||||
sources.add_by_hand(store, "Hand")
|
||||
store.set_affinity(agent.id, "hand", 2)
|
||||
sources.remove_company(store, "hand")
|
||||
assert store.company("hand") is None
|
||||
assert store.company("hand", agent.id) is None
|
||||
with pytest.raises(KeyError):
|
||||
sources.remove_company(store, "hand")
|
||||
|
||||
sub, _found, _closed = sources.set_board(store, "acme", "greenhouse:acme", name="Acme")
|
||||
with pytest.raises(sources.Conflict, match="detach the board"):
|
||||
sources.remove_company(store, "acme")
|
||||
store.upsert_role(posting("1"), sub)
|
||||
sources.detach_board(store, "acme") # closes the role: no board, none open
|
||||
sources.remove_company(store, "acme")
|
||||
assert store.company("acme") is None
|
||||
# The detached subscription stays and is found again by a company of that name.
|
||||
assert store.company_subscription("acme") is not None
|
||||
|
||||
store.add_company("Open", key="open")
|
||||
other = store.add_subscription("search", "jobindex:x", label="x", board="jobindex")
|
||||
item = posting("2")
|
||||
item.raw = {"company": "Open"}
|
||||
store.upsert_role(item, other)
|
||||
with pytest.raises(ValueError, match="open roles"):
|
||||
sources.remove_company(store, "open")
|
||||
|
||||
|
||||
def test_by_hand_lists_the_unboarded_never_opened_first(
|
||||
store: Store, boards: Boards) -> None:
|
||||
sources.add_by_hand(store, "Zeta")
|
||||
sources.add_by_hand(store, "Beta")
|
||||
sources.add_by_hand(store, "Old")
|
||||
sources.add_by_hand(store, "Recent")
|
||||
store.update_company("old", careers_opened_at="2026-08-01T00:00:00+00:00")
|
||||
store.update_company("recent", careers_opened_at="2026-09-20T00:00:00+00:00")
|
||||
sources.set_board(store, "read", "greenhouse:acme", name="Read") # a board: not listed
|
||||
store.add_company("Pleo", key="pleo", ats="teamtailor") # unread, no reason: listed
|
||||
store.add_company("Quiet", key="quiet") # from a search only
|
||||
sources.set_board(store, "gone", "ashby:acme", name="Gone")
|
||||
sources.detach_board(store, "gone") # detached: listed
|
||||
|
||||
assert [c.key for c in sources.by_hand(store)] == [
|
||||
"beta", "gone", "pleo", "zeta", "old", "recent"]
|
||||
|
||||
|
||||
# -------------------------------------------------------------------- CLI
|
||||
|
||||
def _cli(tmp_path: Path, *argv: str) -> int:
|
||||
@@ -289,6 +450,86 @@ def test_cli_seed_prints_counts_and_problems(
|
||||
assert "companies seed: odd: 'nosuch:odd' is not a known board" in captured.err
|
||||
|
||||
|
||||
def test_cli_add_with_one_name_lists_a_company_by_hand_and_with_two_follows_a_board(
|
||||
store: Store, boards: Boards, tmp_path: Path,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
assert _cli(tmp_path, "add", "Revolut", "--careers-url", "https://r.example/jobs",
|
||||
"--note", "login wall") == 0
|
||||
assert json.loads(capsys.readouterr().out) == {"key": "revolut", "hand_reason": "added"}
|
||||
revolut = store.company("revolut")
|
||||
assert revolut is not None
|
||||
assert (revolut.careers_url, revolut.notes, revolut.hand_reason) == (
|
||||
"https://r.example/jobs", "login wall", "added")
|
||||
assert _cli(tmp_path, "add", "Meta", "--reason", "blocked") == 0
|
||||
assert store.company("meta").hand_reason == "blocked" # type: ignore[union-attr]
|
||||
capsys.readouterr()
|
||||
|
||||
assert _cli(tmp_path, "add", "Revolut") == 1
|
||||
assert "on the list already" in capsys.readouterr().err
|
||||
assert _cli(tmp_path, "add", "Odd", "--careers-url", "javascript:alert(1)") == 1
|
||||
assert "http" in capsys.readouterr().err
|
||||
with pytest.raises(SystemExit): # argparse refuses the reason
|
||||
_cli(tmp_path, "add", "Odd", "--reason", "lazy")
|
||||
capsys.readouterr()
|
||||
assert store.company("odd") is None
|
||||
|
||||
# Two words are the board and the company, as before.
|
||||
assert _cli(tmp_path, "add", "greenhouse:acme", "Acme") == 0
|
||||
assert json.loads(capsys.readouterr().out) == {
|
||||
"key": "acme", "board": "greenhouse:acme", "roles": 3}
|
||||
|
||||
|
||||
def test_cli_edit_checked_and_remove_a_company_by_hand(
|
||||
store: Store, boards: Boards, tmp_path: Path,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
store.add_company("Acme", key="acme", notes="keep", hand_reason="unread")
|
||||
assert _cli(tmp_path, "edit", "acme", "--careers-url", "https://acme.example/jobs",
|
||||
"--reason", "robots") == 0
|
||||
assert json.loads(capsys.readouterr().out) == {
|
||||
"key": "acme", "name": "Acme", "careers_url": "https://acme.example/jobs",
|
||||
"notes": "keep", "hand_reason": "robots"}
|
||||
assert _cli(tmp_path, "edit", "acme", "--note", "") == 0
|
||||
assert store.company("acme").notes == "" # type: ignore[union-attr]
|
||||
assert _cli(tmp_path, "edit", "acme", "--careers-url", "ftp://x") == 1
|
||||
assert "http" in capsys.readouterr().err
|
||||
assert _cli(tmp_path, "edit", "nobody", "--note", "x") == 1
|
||||
assert "no company 'nobody'" in capsys.readouterr().err
|
||||
|
||||
assert _cli(tmp_path, "checked", "acme") == 0
|
||||
stamp = json.loads(capsys.readouterr().out)["careers_opened_at"]
|
||||
assert stamp and store.company("acme").careers_opened_at == stamp # type: ignore[union-attr]
|
||||
assert _cli(tmp_path, "checked", "nobody") == 1
|
||||
capsys.readouterr()
|
||||
|
||||
sources.set_board(store, "read", "greenhouse:acme", name="Read")
|
||||
assert _cli(tmp_path, "remove", "read") == 1
|
||||
assert "detach the board first" in capsys.readouterr().err
|
||||
assert _cli(tmp_path, "remove", "acme") == 0
|
||||
assert store.company("acme") is None
|
||||
assert _cli(tmp_path, "remove", "acme") == 1
|
||||
|
||||
|
||||
def test_cli_by_hand_prints_never_opened_first_then_the_oldest_and_the_watch_rating(
|
||||
store: Store, boards: Boards, tmp_path: Path,
|
||||
capsys: pytest.CaptureFixture[str]) -> None:
|
||||
store.add_company("Recent", careers_url="https://recent.example/jobs",
|
||||
hand_reason="gone")
|
||||
store.add_company("Old", hand_reason="robots")
|
||||
store.add_company("Never", careers_url="https://never.example/jobs", hand_reason="added")
|
||||
store.update_company("recent", careers_opened_at="2026-09-20T08:00:00+00:00", watch=0)
|
||||
store.update_company("old", careers_opened_at="2026-08-01T08:00:00+00:00", watch=1)
|
||||
sources.set_board(store, "read", "greenhouse:acme", name="Read")
|
||||
|
||||
assert _cli(tmp_path, "by-hand") == 0
|
||||
lines = capsys.readouterr().out.splitlines()
|
||||
assert [ln.split()[0] for ln in lines[:-1]] == ["Never", "Old", "Recent"]
|
||||
assert lines[0].split() == ["Never", "added", "-", "never", "https://never.example/jobs"]
|
||||
assert lines[1].split() == ["Old", "robots", "yes", "2026-08-01"]
|
||||
assert lines[2].split() == ["Recent", "gone", "no", "2026-09-20",
|
||||
"https://recent.example/jobs"]
|
||||
assert lines[-1] == "3 by hand"
|
||||
|
||||
|
||||
def test_replacing_or_detaching_a_board_forgets_that_it_was_failing(
|
||||
store: Store, boards: Boards) -> None:
|
||||
from app.jobs.pull import FAILING, failing_boards
|
||||
|
||||
Reference in new issue
Block a user