Files
jobboard/tests/test_ats_hibob.py
T
WolfandClaude Opus 5.5 902089a5e2 Runner: readers read from their declaration, ats and search thin over it
plugins/readers/_runner.py takes the guarded fetch, the listing (whole,
paged, one series per filter value unioned by id), completeness from READS,
the sweep of a board over the page cap across pulls, the 10% guard on a
filtered or empty="suspect" read, facets kept a day, the detail reads, the
raw an Item carries and the failure bookkeeping out of plugins/ats.py.
Ask comes from a subscription's params (ask_for, open for the reach), with
a declared key resolved into Ask.params["key"] and refused when missing.

The runtime robots.txt check goes (decided at build time, READS.robots).
plugins/search.py reads the providers of readers.PROVIDERS through the
runner and applies the saved pages param. A filtered board's close keeps
roles with a vote or an application. DETAIL_FIELDS gain places, teaser,
country and employment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 09:28:33 +02:00

195 lines
8.5 KiB
Python

"""The HiBob host module against saved answers: Liquidia's board trimmed to
five roles and Dixa's whole one, 2026-09-29. No network."""
from __future__ import annotations
import json
import sys
from pathlib import Path
from typing import Any
import httpx
import pytest
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from app.jobs.discover import boards_in # noqa: E402
from plugins import ats, readers # noqa: E402
from plugins.readers import hibob # noqa: E402
FIXTURES = ROOT / "tests" / "fixtures" / "ats"
BOARD = (FIXTURES / "hibob.json").read_bytes()
DIXA = (FIXTURES / "hibob-dixa.json").read_bytes()
API = "https://liquidia.careers.hibob.com/api/job-ad"
def test_rows_carry_the_ads_texts_place_and_date() -> None:
rows = hibob.parse(BOARD, "liquidia")
assert len(rows) == 5
first = rows[0]
assert first["source_id"] == "c328a12c-1c6a-4d34-bfa7-ac322bc32c5d"
assert first["title"] == "Senior Vice President, Head of Clinical Operations"
assert first["url"] == \
"https://liquidia.careers.hibob.com/jobs/c328a12c-1c6a-4d34-bfa7-ac322bc32c5d"
assert first["department"] == "1023-Clin Ops - R&D"
assert first["location"] == "USA, United States"
assert first["remote"] == "hybrid" and rows[1]["remote"] == "remote"
assert first["posted"] is not None and first["posted"].isoformat() == \
"2026-09-15T19:22:14.562309+00:00" # nine fractional digits in the answer
text = first["description"]
# The description, the responsibilities, the requirements and the benefits, in that order,
# as text with its entities read.
assert text.startswith("Liquidia is deeply passionate")
assert text.index("Leadership & Strategy") < text.index("Bachelor\u2019s degree required")
assert "<" not in text and "&amp;" not in text and "\xa0" not in text
assert first["salary_text"] == "" and first["currency"] == ""
def test_a_board_of_general_applications_reads_as_it_is() -> None:
rows = hibob.parse(DIXA, "dixa")
assert [(r["title"], r["location"], r["remote"]) for r in rows] == [
("Expression of interest", "Copenhagen, Denmark", "hybrid"),
("Expression of interest", "London, United Kingdom", "onsite")]
assert rows[1]["description"].startswith("We're always excited")
def _one(**fields: Any) -> bytes:
return json.dumps({"jobAdDetails": [{"id": "a", "title": "Baker", **fields}]}).encode()
@pytest.mark.parametrize(("pay", "columns", "text"), [
({"payTransparencyMinSalary": 50000, "payTransparencyMaxSalary": 70000,
"payTransparencySalaryCurrency": "EUR", "payTransparencySalaryPayPeriod": "Yearly"},
(50000, 70000, "EUR"), "EUR 50,000 to 70,000 per year"),
({"payTransparencyMinSalary": 4000, "payTransparencyMaxSalary": None,
"payTransparencySalaryCurrency": "DKK", "payTransparencySalaryPayPeriod": "MONTH"},
(48000, None, "DKK"), "DKK from 4,000 per month"),
# An hourly rate stays out of the yearly columns and in the text.
({"payTransparencyMinSalary": 30, "payTransparencyMaxSalary": 40,
"payTransparencySalaryCurrency": "USD", "payTransparencySalaryPayPeriod": "hourly"},
(None, None, ""), "USD 30 to 40 per hour"),
({}, (None, None, ""), ""),
])
def test_pay_is_read_by_its_period(pay: dict[str, Any], columns: tuple[Any, ...],
text: str) -> None:
row = hibob.parse(_one(**pay), "acme")[0]
assert (row["salary_min"], row["salary_max"], row["currency"]) == columns
assert row["salary_text"] == text
def test_the_place_leaves_the_country_off_where_the_site_names_it() -> None:
for fields, want in (({"site": "Denmark", "country": "Denmark"}, "Denmark"),
({"site": "Copenhagen", "country": "Denmark"}, "Copenhagen, Denmark"),
({"site": "", "country": "Denmark"}, "Denmark"),
({}, "")):
assert hibob.parse(_one(**fields), "acme")[0]["location"] == want
def test_an_ad_without_a_title_or_id_is_skipped_and_an_empty_board_is_empty() -> None:
body = json.dumps({"jobAdDetails": [{"id": "a", "title": " "}, {"title": "x"},
{"id": "c", "title": "Cook"}]}).encode()
assert [r["source_id"] for r in hibob.parse(body, "acme")] == ["c"]
assert hibob.parse(b'{"filterGroups": {}, "jobAdDetails": []}', "acme") == []
# ------------------------------------------------------------ the fetch
def test_the_page_sends_the_company_header_and_states_no_total() -> None:
seen: list[tuple[str, dict[str, str] | None]] = []
def get(url: str, *, method: str = "GET", payload: Any = None,
headers: dict[str, str] | None = None) -> bytes:
seen.append((url, headers))
return BOARD
data, results, total, cursor = hibob.page(get, "Liquidia", None)
assert seen == [(API, {"companyIdentifier": "liquidia", "Accept": "application/json"})]
assert len(results) == 5 and all(r["id"] for r in results)
assert total is None and cursor is None
assert len(hibob.rows(data, "liquidia")) == 5
def test_a_body_without_the_ads_is_not_a_board() -> None:
with pytest.raises(ValueError, match="not a HiBob board"):
hibob.page(lambda url, **kw: b'{"error": "unauthorized"}', "acme", None)
@pytest.fixture
def web(monkeypatch: pytest.MonkeyPatch) -> dict[str, Any]:
answers: dict[str, Any] = {}
seen: list[tuple[str, dict[str, str] | None]] = []
def fake_get(client, url, host, slug, *, method="GET", payload=None, headers=None,
www_twin=False):
seen.append((url, headers))
if not ats._allowed_host(host, slug)(httpx.URL(url).host):
raise ats._Refused(url)
answer = answers[url]
if isinstance(answer, BaseException):
raise answer
return answer
monkeypatch.setattr(ats, "_get", fake_get)
return {"answers": answers, "seen": seen}
def test_the_board_is_one_request_and_complete(web: dict[str, Any]) -> None:
web["answers"][API] = BOARD
with httpx.Client() as client:
rows, complete = ats._fetch_rows(client, "hibob:liquidia")
assert len(rows) == 5 and complete
assert [url for url, _ in web["seen"]] == [API]
assert web["seen"][0][1]["companyIdentifier"] == "liquidia"
def test_an_empty_board_is_complete_and_a_401_is_a_failure(web: dict[str, Any]) -> None:
web["answers"]["https://acme.careers.hibob.com/api/job-ad"] = b'{"jobAdDetails": []}'
request = httpx.Request("GET", API)
web["answers"][API] = httpx.HTTPStatusError(
"401", request=request, response=httpx.Response(401, request=request))
with httpx.Client() as client:
assert ats._fetch_rows(client, "hibob:acme") == ([], True)
with pytest.raises(httpx.HTTPStatusError):
ats._fetch_rows(client, "hibob:liquidia")
# ------------------------------------------------------- slugs and hosts
def test_the_module_is_registered_as_a_paged_host() -> None:
assert readers.HOSTS["hibob"] is hibob and ats.HOSTS["hibob"] == "HiBob"
assert hibob.NAME == "hibob" and not getattr(hibob, "KEEP_CASE", False)
assert hasattr(hibob, "page") and not hasattr(hibob, "detail")
def test_the_urls_and_the_allowed_host_follow_the_slug() -> None:
assert hibob.careers_url("dixa") == "https://dixa.careers.hibob.com/"
assert hibob.robots_page("dixa") == "https://dixa.careers.hibob.com/"
allow = hibob.allowed("Dixa")
assert allow("dixa.careers.hibob.com") and allow("DIXA.CAREERS.HIBOB.COM")
for host in ("careers.hibob.com", "other.careers.hibob.com", "dixa.hibob.com",
"dixa.careers.hibob.com.evil.example", "localhost"):
assert not allow(host)
@pytest.mark.parametrize("slug", ["dixa", "Dixa", "hibob-e360", "jp95"])
def test_a_slug_is_one_dns_label(slug: str) -> None:
assert ats.is_known_target(f"hibob:{slug}")
@pytest.mark.parametrize("slug", [
"", "a@b", "a#b", "a?b", "..", ".", "a%2fb", "a/b", "a:443", "a b", "acme\n", " acme",
"acme ", "localhost.evil", "127.0.0.1", "a.b", "a_b", "a\\b", "évil",
])
def test_a_hostile_slug_is_refused(slug: str) -> None:
assert not hibob.slug_ok(slug)
assert not ats.is_known_target(f"hibob:{slug}")
def test_discovery_finds_the_subdomain() -> None:
page = ('<a href="https://dixa.careers.hibob.com/">Careers</a>'
'<a href="https://Liquidia.careers.hibob.com/jobs/abc">Role</a>'
'<a href="https://www.hibob.com/careers">HiBob itself</a>')
assert [(h, s) for h, s, _ in boards_in(page)] == [("hibob", "dixa"), ("hibob", "liquidia")]