"""The Lever host module's places, country and employment, against a small saved board, and an answer that is no board. No network. The pay and the plain row are in `test_ats.py`.""" 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 plugins import ats # noqa: E402 from plugins.readers import Ask, lever # noqa: E402 BOARD = (ROOT / "tests" / "fixtures" / "ats" / "lever-places.json").read_bytes() def test_every_place_of_all_locations_is_kept_once() -> None: several, one = lever.parse(BOARD, "acme") assert several["places"] == [{"text": "London", "remote": None}, {"text": "Stockholm", "remote": None}] assert several["location"] == "London; Stockholm" assert one["places"] == [{"text": "Berlin", "remote": None}] def test_the_country_is_only_taken_for_a_role_at_one_place() -> None: several, one = lever.parse(BOARD, "acme") assert "country" not in several and one["country"] == "DE" def test_the_commitment_is_the_hosts_word() -> None: several, one = lever.parse(BOARD, "acme") assert several["employment"] == "Full-time" and one["employment"] == "Permanent" def test_an_answer_that_is_not_a_list_raises_and_an_empty_list_is_no_roles() -> None: with pytest.raises(ValueError, match="JSON dict, not a list"): lever.parse(b'{"ok": false, "error": "Document not found"}', "acme") assert lever.parse(b"[]", "acme") == [] def test_an_error_document_with_a_200_fails_the_read_and_stamps_nothing( monkeypatch: pytest.MonkeyPatch) -> None: """It used to read as a complete board with no roles, which the settle closed whole under ten roles, where the 10% guard does not hold.""" monkeypatch.setattr(ats, "_get", lambda *a, **kw: b'{"ok": false}') source = ats.ATSSource({"boards": [{"url": "lever:acme", "label": "Acme", "params": {}}], "run": "r"}) source.state = {} assert list(source.fetch()) == [] assert "ats:ok:lever:acme" not in source.state assert json.loads(source.state["ats:failing:lever:acme"])["reason"].startswith( "ValueError: Lever's answer is a JSON dict") def test_it_declares_a_whole_listing_of_trusted_dates_and_its_robots_record() -> None: reads = lever.READS assert (reads.listing, reads.text, reads.places) == ("whole", "listing", "many") assert reads.fields.posted == "trusted" and reads.fields.country == "stated" assert reads.robots.startswith("read: ") and "(checked 2026-09-30)" in reads.robots assert lever.feed_url("eu/tomtom", Ask()) == "https://api.eu.lever.co/v0/postings/tomtom?mode=json"