"""SmartRecruiters: the place, country, level and employment a posting states. No network: the shapes are those of Bosch's board, read on 2026-09-30.""" from __future__ import annotations 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 desk.sources import strip_html # noqa: E402 from plugins.readers import Ask, _runner, smartrecruiters # noqa: E402 FIXTURES = ROOT / "tests" / "fixtures" / "ats" def _posting(**fields: object) -> dict: return {"id": "1", "name": "Engineer", "releasedDate": "2026-09-30T06:57:01.920Z", "location": {"city": "Hatvan", "country": "hu", "remote": False, "fullLocation": "Hatvan, , Hungary"}, **fields} def _rows(*postings: dict) -> list[dict]: return smartrecruiters.rows({"content": list(postings)}, "BoschGroup") 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", "detail", "suspect") assert reads.fields.posted == "trusted" and reads.fields.seniority == "stated" assert reads.robots.startswith("api: no robots.txt check needed") def test_page_reads_by_offset_and_takes_the_ask() -> None: asked: list[str] = [] def get(url: str, **_: object) -> bytes: asked.append(url) return (FIXTURES / "smartrecruiters.json").read_bytes() _data, results, total, cursor = smartrecruiters.page(get, "Acme", None, Ask()) assert asked == ["https://api.smartrecruiters.com/v1/companies/Acme/postings" "?offset=0&limit=100"] assert (len(results), total, cursor) == (2, 3, 2) def test_the_place_is_one_clean_line_with_its_remote_flag_and_country() -> None: [row] = _rows(_posting()) assert row["places"] == [{"text": "Hatvan, Hungary", "remote": False}] # ", ," gone assert row["location"] == "Hatvan, Hungary" and row["country"] == "hu" [remote] = _rows(_posting(location={"remote": True, "fullLocation": "Remote", "country": ""})) assert remote["places"] == [{"text": "Remote", "remote": True}] and remote["country"] is None [none] = _rows(_posting(location={})) assert none["places"] == [] and none["location"] == "" def test_the_stated_level_and_employment_are_the_hosts_words() -> None: [row] = _rows(_posting(experienceLevel={"id": "internship", "label": "Internship"}, typeOfEmployment={"id": "intern", "label": "Intern"})) assert (row["seniority"], row["employment"]) == ("internship", "intern") [row] = _rows(_posting(experienceLevel={"id": "mid_senior_level"})) assert row["seniority"] == "mid_senior_level" [row] = _rows(_posting()) assert row["seniority"] is None and row["employment"] is None 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": "

Build & run

"}}}}).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"]