Ashby, BambooHR, Deel, Eightfold, Gem, Greenhouse, HiBob, HR Manager, Jibe, Jobylon and Lever move to feed_url(slug, ask) and page(get, slug, cursor, ask), declare READS with the robots decision, and drop robots_page. Rows carry places (Ashby secondaryLocations, Lever allLocations, Greenhouse offices in place of a Hybrid placeholder), Jobylon keeps its summary as teaser and maps experience and employment, Eightfold reads creationTs as the posting date and Ashby reads workplaceType. Fixtures <name>-places.* and jobylon-teaser.html drive the conformance checks; the eleven names leave UNDECLARED. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
206 lines
9.0 KiB
Python
206 lines
9.0 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 Ask, 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 "&" 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, Ask())
|
|
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, Ask())
|
|
|
|
|
|
def test_the_board_is_one_request_with_the_company_header() -> 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, Ask())
|
|
assert len(hibob.rows(data, "liquidia")) == 5 and cursor is None
|
|
assert [url for url, _ in seen] == [API]
|
|
assert seen[0][1] is not None and seen[0][1]["companyIdentifier"] == "liquidia"
|
|
|
|
|
|
def test_an_empty_board_is_no_rows_and_a_401_reaches_the_caller() -> None:
|
|
data, results, _total, _cursor = hibob.page(
|
|
lambda url, **kw: b'{"jobAdDetails": []}', "acme", None, Ask())
|
|
assert hibob.rows(data, "acme") == [] and results == []
|
|
request = httpx.Request("GET", API)
|
|
|
|
def refused(url: str, **kw: Any) -> bytes:
|
|
raise httpx.HTTPStatusError("401", request=request,
|
|
response=httpx.Response(401, request=request))
|
|
|
|
with pytest.raises(httpx.HTTPStatusError):
|
|
hibob.page(refused, "liquidia", None, Ask())
|
|
|
|
|
|
def test_each_ad_names_one_site_and_the_host_lists_a_copy_per_site() -> None:
|
|
dixa = hibob.parse(DIXA, "dixa")
|
|
assert [r["places"] for r in dixa] == [
|
|
[{"text": "Copenhagen, Denmark", "remote": False}],
|
|
[{"text": "London, United Kingdom", "remote": False}]]
|
|
assert {r["title"] for r in dixa} == {"Expression of interest"}
|
|
assert len({r["source_id"] for r in dixa}) == 2
|
|
|
|
|
|
def test_the_employment_type_is_mapped_and_a_permanent_one_is_left_unmapped() -> None:
|
|
rows = hibob.parse(BOARD, "liquidia")
|
|
assert rows[0]["employment"] == "full_time" # "Regular Full Time"
|
|
assert "employment" not in hibob.parse(DIXA, "dixa")[0] # "Permanent"
|
|
|
|
|
|
def test_it_declares_copies_with_a_page_and_a_robots_decision() -> None:
|
|
reads = hibob.READS
|
|
assert (reads.listing, reads.text, reads.places, reads.complete) == (
|
|
"paged", "listing", "copies", "end")
|
|
assert reads.robots.startswith("read: robots.txt allows")
|
|
assert not hasattr(hibob, "robots_page")
|
|
|
|
|
|
# ------------------------------------------------------- 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/"
|
|
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")]
|