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:
1 parent
a19c528e3f
commit
70aa4b3117
6 files changed
+176
-11
No files matched your search
@@ -7,12 +7,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, smartrecruiters # noqa: E402
|
||||
from desk.sources import strip_html # noqa: E402
|
||||
from plugins.readers import Ask, _runner, smartrecruiters # noqa: E402
|
||||
|
||||
FIXTURES = ROOT / "tests" / "fixtures" / "ats"
|
||||
|
||||
@@ -30,7 +33,7 @@ def _rows(*postings: dict) -> list[dict]:
|
||||
def test_the_declaration_says_what_the_list_gives() -> None:
|
||||
reads = smartrecruiters.READS
|
||||
assert (reads.listing, reads.page_size, reads.places, reads.text, reads.empty) == \
|
||||
("paged", 100, "one", "none", "suspect")
|
||||
("paged", 100, "one", "detail", "suspect")
|
||||
assert reads.fields.posted == "trusted" and reads.fields.seniority == "stated"
|
||||
assert reads.robots.startswith("api: no robots.txt check needed")
|
||||
|
||||
@@ -72,3 +75,45 @@ def test_the_saved_page_still_reads() -> None:
|
||||
data = json.loads((FIXTURES / "smartrecruiters.json").read_bytes())
|
||||
assert [r["location"] for r in smartrecruiters.rows(data, "Acme")] == ["Berlin, Germany",
|
||||
"Remote"]
|
||||
|
||||
|
||||
def test_detail_reads_the_ad_without_the_company_blurb() -> None:
|
||||
asked: list[str] = []
|
||||
|
||||
def get(url: str, **_: object) -> bytes:
|
||||
asked.append(url)
|
||||
return (FIXTURES / "smartrecruiters-detail.json").read_bytes()
|
||||
|
||||
found = smartrecruiters.detail(get, "deliveryhero", {"source_id": "744000151349134"})
|
||||
assert asked == ["https://api.smartrecruiters.com/v1/companies/deliveryhero/postings/"
|
||||
"744000151349134"]
|
||||
assert set(found) == {"description"} and set(found) <= set(_runner.DETAIL_FIELDS)
|
||||
text = found["description"]
|
||||
data = json.loads((FIXTURES / "smartrecruiters-detail.json").read_bytes())
|
||||
sections = data["jobAd"]["sections"]
|
||||
assert data["jobAd"]["sections"]["companyDescription"]["text"]
|
||||
assert strip_html(sections["companyDescription"]["text"])[:60] not in text
|
||||
assert strip_html(sections["jobDescription"]["text"])[:60] in text
|
||||
assert strip_html(sections["qualifications"]["text"])[-40:] in text
|
||||
assert strip_html(sections["additionalInformation"]["text"])[-40:] in text
|
||||
assert "<" not in text and " " not in text and len(text) > 1500
|
||||
|
||||
|
||||
def test_detail_leaves_out_a_section_the_ad_lacks() -> None:
|
||||
body = json.dumps({"jobAd": {"sections": {
|
||||
"jobDescription": {"text": "<p>Build & run</p><ul><li>APIs</li></ul>"}}}}).encode()
|
||||
assert smartrecruiters.detail(lambda url, **_: body, "Acme", {"source_id": "7"}) == \
|
||||
{"description": "Build & run APIs"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("body", [b"{}", b'{"jobAd": {}}', b'{"jobAd": null}', b"[]"])
|
||||
def test_detail_refuses_an_answer_that_is_not_a_posting(body: bytes) -> None:
|
||||
with pytest.raises(ValueError, match="not a SmartRecruiters posting"):
|
||||
smartrecruiters.detail(lambda url, **_: body, "Acme", {"source_id": "7"})
|
||||
|
||||
|
||||
def test_detail_cannot_add_to_the_path() -> None:
|
||||
asked: list[str] = []
|
||||
smartrecruiters.detail(lambda url, **_: asked.append(url) or b'{"jobAd":{"sections":{}}}',
|
||||
"Acme", {"source_id": "7/../x"})
|
||||
assert asked == ["https://api.smartrecruiters.com/v1/companies/Acme/postings/7%2F..%2Fx"]
|
||||
Reference in new issue
Block a user