Read the text of SmartRecruiters and Workable roles through detail, keeping Workable's shortcode in the row

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 13:23:58 +02:00
1 parent a19c528e3f
commit 70aa4b3117
6 files changed
+176 -11

No files matched your search

+50 -2
View File
@@ -8,12 +8,15 @@ import json
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from plugins.readers import Ask, workable # noqa: E402
from desk.sources import strip_html # noqa: E402
from plugins.readers import Ask, _runner, workable # noqa: E402
FIXTURES = ROOT / "tests" / "fixtures" / "ats"
@@ -25,7 +28,7 @@ def _rows() -> list[dict]:
def test_the_declaration_says_what_the_list_gives() -> None:
reads = workable.READS
assert (reads.listing, reads.page_size, reads.places, reads.text) == \
("paged", 10, "many", "none")
("paged", 10, "many", "detail")
assert reads.fields.posted == "trusted" and reads.fields.employment == "stated"
assert reads.robots.startswith("api: no robots.txt check needed")
@@ -61,3 +64,48 @@ def test_the_stated_hours_are_the_hosts_word() -> None:
def test_the_shape_of_a_real_list_answer_is_read() -> None:
data = json.loads((FIXTURES / "workable-places.json").read_bytes())
assert workable.rows(data, "acme")[0]["url"] == "https://apply.workable.com/acme/j/AAA111/"
def test_a_row_keeps_the_shortcode_the_detail_url_needs() -> None:
first, remote, oslo = _rows()
assert [r["source_id"] for r in (first, remote, oslo)] == ["8001", "8002", "8003"]
assert [r["shortcode"] for r in (first, remote, oslo)] == ["AAA111", "BBB222", "CCC333"]
def test_detail_reads_description_requirements_and_benefits() -> None:
asked: list[str] = []
body = (FIXTURES / "workable-detail.json").read_bytes()
def get(url: str, **_: object) -> bytes:
asked.append(url)
return body
row = {"source_id": "6125026", "shortcode": "DB4D7C0EC8"}
found = workable.detail(get, "huggingface", row)
assert asked == ["https://apply.workable.com/api/v2/accounts/huggingface/jobs/DB4D7C0EC8"]
assert set(found) == {"description"} and set(found) <= set(_runner.DETAIL_FIELDS)
text, data = found["description"], json.loads(body)
for key in ("description", "requirements", "benefits"):
assert strip_html(data[key])[:40] in text
assert text.index(strip_html(data["description"])[:40]) < \
text.index(strip_html(data["benefits"])[:40])
assert "<" not in text and " " not in text and len(text) > 1500
def test_detail_joins_what_is_there_and_unescapes() -> None:
body = json.dumps({"description": "<p>Build &amp; run</p>", "requirements": None,
"benefits": "<ul><li>Pension</li></ul>"}).encode()
assert workable.detail(lambda url, **_: body, "acme", {"shortcode": "AAA111"}) == \
{"description": "Build & run Pension"}
@pytest.mark.parametrize("body", [b"{}", b"[]", b'{"title": "x"}'])
def test_detail_refuses_an_answer_that_is_not_a_role(body: bytes) -> None:
with pytest.raises(ValueError, match="not a Workable role"):
workable.detail(lambda url, **_: body, "acme", {"shortcode": "AAA111"})
@pytest.mark.parametrize("row", [{}, {"shortcode": ""}, {"shortcode": "a/b"}, {"shortcode": ".."}])
def test_detail_needs_a_plain_shortcode(row: dict) -> None:
with pytest.raises(ValueError, match="shortcode"):
workable.detail(lambda url, **_: b"{}", "acme", row)