"""Workable: every location of a role, the country and the hours it states. No network: the fixture has the shape of Hugging Face's board, read on 2026-09-30.""" from __future__ import annotations import json import logging 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 FIXTURES = ROOT / "tests" / "fixtures" / "ats" def _rows() -> list[dict]: return workable.parse((FIXTURES / "workable-places.json").read_bytes(), "acme") 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") assert reads.fields.posted == "trusted" and reads.fields.employment == "stated" assert reads.robots.startswith("api: no robots.txt check needed") def test_page_takes_the_ask_and_posts_the_same_body() -> None: sent: list[dict] = [] def get(url: str, *, method: str = "GET", payload: dict | None = None, **_: object) -> bytes: sent.append({"url": url, "method": method, "payload": payload}) return b'{"total": 0, "results": []}' workable.page(get, "acme", None, Ask()) workable.page(get, "acme", "tok", Ask()) assert [s["payload"] for s in sent] == [{}, {"token": "tok"}] def test_every_location_of_a_role_is_a_place_once() -> None: first, remote, oslo = _rows() assert [p["text"] for p in first["places"]] == ["Berlin, Germany", "Munich, Bavaria, Germany", "Paris, France"] assert first["location"] == "Berlin, Germany; Munich, Bavaria, Germany; Paris, France" assert first["country"] is None # DE and FR assert [p["remote"] for p in first["places"]] == [False] * 3 assert remote["places"] == [{"text": "France", "remote": True}] assert remote["country"] == "FR" # A list-less answer (the older shape) still gives its one place. assert oslo["places"] == [{"text": "Oslo, Norway", "remote": False}] assert oslo["country"] == "NO" def test_the_stated_hours_are_mapped_and_an_unknown_type_is_logged( caplog: pytest.LogCaptureFixture) -> None: with caplog.at_level(logging.DEBUG, logger=workable.__name__): rows = _rows() assert [r["employment"] for r in rows] == ["full_time", "part_time", None] assert [r.getMessage() for r in caplog.records] == ["workable: unknown type 'volunteer'"] 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/"