64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
"""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 sys
|
|
from pathlib import Path
|
|
|
|
|
|
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 "country" not in first # prep derives it from the places
|
|
assert [p["remote"] for p in first["places"]] == [False] * 3
|
|
assert remote["places"] == [{"text": "France", "remote": True}]
|
|
# A list-less answer (the older shape) still gives its one place.
|
|
assert oslo["places"] == [{"text": "Oslo, Norway", "remote": False}]
|
|
|
|
|
|
def test_the_stated_hours_are_the_hosts_word() -> None:
|
|
assert [r["employment"] for r in _rows()] == ["full", "part", "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/"
|