Every import, test and live doc follows the new path; behaviour is unchanged. tests/test_atshosts.py becomes tests/test_readers.py. plan-readers.md and review-ingest.md keep the old name, since they describe the state before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
213 lines
9.7 KiB
Python
213 lines
9.7 KiB
Python
"""The Rippling host module against saved answers: a listing trimmed from
|
|
Rippling's own board, Prisma's whole listing, and two role records,
|
|
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 rippling # noqa: E402
|
|
|
|
FIXTURES = ROOT / "tests" / "fixtures" / "ats"
|
|
BOARD = (FIXTURES / "rippling.json").read_bytes()
|
|
PRISMA = (FIXTURES / "rippling-prisma.json").read_bytes()
|
|
FEED = "https://api.rippling.com/platform/api/ats/v1/board/rippling/jobs"
|
|
DIRECTOR = "2f2ae4c8-ec56-4d1f-8f2a-0d295674e19c"
|
|
|
|
|
|
def test_rows_merge_one_entry_per_place_into_one_role() -> None:
|
|
rows = rippling.parse(BOARD, "rippling")
|
|
assert [r["source_id"][:8] for r in rows] == [
|
|
"75ad50c6", "94486f41", "2f2ae4c8", "46b4af52", "19ae5b34"]
|
|
by_id = {r["source_id"][:8]: r for r in rows}
|
|
assert by_id["94486f41"]["location"] == "Pittsburgh, PA; Cleveland, OH"
|
|
assert by_id["2f2ae4c8"]["location"] == "San Francisco, CA; Seattle, WA; New York, NY"
|
|
first = rows[0]
|
|
assert first["title"] == "Account Executive, Broker Channel (Austin & San Antonio)"
|
|
assert first["url"] == "https://ats.rippling.com/rippling/jobs/75ad50c6-778f-42ee-9c63-70d1cd687202"
|
|
assert first["department"] == "Sales" and first["location"] == "Austin, TX"
|
|
assert first["description"] == "" and first["salary_text"] == "" and first["posted"] is None
|
|
|
|
|
|
def test_remote_is_true_only_when_every_place_is_a_remote_one() -> None:
|
|
by_id = {r["source_id"][:8]: r for r in rippling.parse(BOARD, "rippling")}
|
|
assert by_id["46b4af52"]["remote"] is True and by_id["19ae5b34"]["remote"] is True
|
|
assert by_id["75ad50c6"]["remote"] is None # an office label says nothing either way
|
|
mixed = json.dumps([
|
|
{"uuid": "abcdefgh-1", "name": "A", "workLocation": {"label": "Remote (Germany)"}},
|
|
{"uuid": "abcdefgh-1", "name": "A", "workLocation": {"label": "Berlin"}}]).encode()
|
|
assert rippling.parse(mixed, "x")[0]["remote"] is None
|
|
|
|
|
|
def test_prisma_board_reads_two_roles() -> None:
|
|
rows = rippling.parse(PRISMA, "prisma-careers")
|
|
assert [(r["title"], r["department"], r["location"], r["remote"]) for r in rows] == [
|
|
("General Applications: Engineering", "Engineering", "Remote (Germany)", True),
|
|
("General Applications: Product", "Product", "Remote (Germany)", True)]
|
|
|
|
|
|
def test_an_empty_board_is_no_roles_and_an_error_answer_is_not_a_board() -> None:
|
|
assert rippling.parse(b"[]", "acme") == []
|
|
with pytest.raises(ValueError, match="not a Rippling board"):
|
|
rippling.parse(b'{"error_code":"RESOURCE_NOT_FOUND"}', "acme")
|
|
|
|
|
|
def test_an_entry_without_a_title_or_a_plain_id_is_skipped() -> None:
|
|
body = json.dumps([{"uuid": "abcdefgh-1", "name": " "}, {"name": "B"},
|
|
{"uuid": "../../x", "name": "C"},
|
|
{"uuid": "abcdefgh-2", "name": "D"}]).encode()
|
|
assert [r["source_id"] for r in rippling.parse(body, "acme")] == ["abcdefgh-2"]
|
|
|
|
|
|
# ---------------------------------------------------------------- detail
|
|
|
|
def _get(answer: bytes, asked: list[str] | None = None) -> Any:
|
|
def get(url: str, *, method: str = "GET", payload: Any = None,
|
|
headers: dict[str, str] | None = None) -> bytes:
|
|
if asked is not None:
|
|
asked.append(url)
|
|
return answer
|
|
return get
|
|
|
|
|
|
def test_detail_reads_description_places_date_and_a_single_yearly_range() -> None:
|
|
row = {r["source_id"]: r for r in rippling.parse(BOARD, "rippling")}[DIRECTOR]
|
|
asked: list[str] = []
|
|
found = rippling.detail(_get((FIXTURES / "rippling-role.json").read_bytes(), asked),
|
|
"rippling", row)
|
|
assert asked == [f"https://api.rippling.com/platform/api/ats/v1/board/rippling/jobs/{DIRECTOR}"]
|
|
assert set(found) <= set(ats.DETAIL_FIELDS)
|
|
assert found["description"].startswith("About The Role")
|
|
assert "<" not in found["description"]
|
|
assert found["location"] == "San Francisco, CA; Seattle, WA; New York, NY"
|
|
assert found["posted"] is not None and found["posted"].isoformat() == \
|
|
"2025-04-07T12:29:19.348000-07:00"
|
|
assert (found["salary_min"], found["salary_max"], found["currency"]) == (216000, 378000, "USD")
|
|
|
|
|
|
def test_detail_without_pay_leaves_the_pay_columns_out() -> None:
|
|
found = rippling.detail(_get((FIXTURES / "rippling-role-2.json").read_bytes()),
|
|
"prisma-careers", {"source_id": "x"})
|
|
assert found["description"].startswith("What is it like to work at Prisma?")
|
|
assert found["location"] == "Remote (Germany)"
|
|
assert not {"salary_min", "salary_max", "currency"} & set(found)
|
|
|
|
|
|
@pytest.mark.parametrize("ranges", [
|
|
[],
|
|
[{"currency": "USD", "frequency": "HOUR", "rangeStart": 40, "rangeEnd": 60}],
|
|
[{"currency": "USD", "frequency": "YEAR", "rangeStart": 1, "rangeEnd": 2},
|
|
{"currency": "USD", "frequency": "YEAR", "rangeStart": 3, "rangeEnd": 4}], # several zones
|
|
[{"currency": "", "frequency": "YEAR", "rangeStart": 1, "rangeEnd": 2}],
|
|
])
|
|
def test_only_one_yearly_range_with_a_currency_fills_the_columns(ranges: list[Any]) -> None:
|
|
body = json.dumps({"description": {"role": "<p>x</p>"}, "payRangeDetails": ranges}).encode()
|
|
found = rippling.detail(_get(body), "acme", {"source_id": "x"})
|
|
assert not {"salary_min", "salary_max", "currency"} & set(found)
|
|
assert found["description"] == "x" and found["posted"] is None
|
|
|
|
|
|
def test_a_monthly_range_is_made_yearly_and_the_company_text_stands_in_for_a_missing_role_text(
|
|
) -> None:
|
|
body = json.dumps({"description": {"company": "<p>About us & more</p>", "role": ""},
|
|
"payRangeDetails": [{"currency": "EUR", "frequency": "MONTH",
|
|
"rangeStart": 3000, "rangeEnd": None}]}).encode()
|
|
found = rippling.detail(_get(body), "acme", {"source_id": "x"})
|
|
assert found["description"] == "About us & more"
|
|
assert (found["salary_min"], found["salary_max"], found["currency"]) == (36000, None, "EUR")
|
|
|
|
|
|
@pytest.fixture
|
|
def web(monkeypatch: pytest.MonkeyPatch) -> dict[str, Any]:
|
|
answers: dict[str, Any] = {}
|
|
asked: list[str] = []
|
|
|
|
def fake_get(client, url, host, slug, *, method="GET", payload=None, headers=None,
|
|
www_twin=False):
|
|
asked.append(url)
|
|
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, "asked": asked}
|
|
|
|
|
|
def test_the_board_is_one_request_and_complete(web: dict[str, Any]) -> None:
|
|
web["answers"][FEED] = BOARD
|
|
with httpx.Client() as client:
|
|
rows, complete = ats._fetch_rows(client, "rippling:rippling")
|
|
assert len(rows) == 5 and complete and web["asked"] == [FEED]
|
|
|
|
|
|
def test_robots_are_read_from_the_site_and_disallow_only_internal(
|
|
web: dict[str, Any]) -> None:
|
|
web["answers"]["https://ats.rippling.com/robots.txt"] = b"User-agent: *\nDisallow: /internal/\n"
|
|
with httpx.Client() as client:
|
|
ats._check_robots(client, "rippling:prisma-careers")
|
|
web["answers"]["https://ats.rippling.com/robots.txt"] = b"User-agent: *\nDisallow: /\n"
|
|
with pytest.raises(ats._Disallowed):
|
|
ats._check_robots(client, "rippling:prisma-careers")
|
|
|
|
|
|
# ------------------------------------------------------- slugs and hosts
|
|
|
|
def test_the_module_is_registered_as_a_feed_host_with_detail() -> None:
|
|
assert readers.HOSTS["rippling"] is rippling and ats.HOSTS["rippling"] == "Rippling"
|
|
assert rippling.NAME == "rippling" and rippling.KEEP_CASE
|
|
assert hasattr(rippling, "detail") and not hasattr(rippling, "page")
|
|
|
|
|
|
def test_the_urls_and_the_robots_page() -> None:
|
|
assert rippling.feed_url("rippling") == FEED
|
|
assert rippling.careers_url("prisma-careers") == "https://ats.rippling.com/prisma-careers/jobs"
|
|
assert rippling.robots_page("prisma-careers") == rippling.careers_url("prisma-careers")
|
|
allow = rippling.allowed("rippling")
|
|
assert allow("api.rippling.com") and allow("ATS.RIPPLING.COM")
|
|
for host in ("rippling.com", "www.rippling.com", "api.rippling.com.evil.example", "localhost"):
|
|
assert not allow(host)
|
|
|
|
|
|
@pytest.mark.parametrize("slug", ["rippling", "prisma-careers", "Acme_2", "9x"])
|
|
def test_a_slug_is_one_path_segment(slug: str) -> None:
|
|
assert ats.is_known_target(f"rippling:{slug}")
|
|
|
|
|
|
@pytest.mark.parametrize("slug", [
|
|
"", "a@b", "a#b", "a?b", "..", ".", "a%2fb", "%2f", "a/b", "a:443", "a b", "acme\n",
|
|
" acme", "acme ", "127.0.0.1", "a.b", "_x", "-x", "a\\b", "évil",
|
|
])
|
|
def test_a_hostile_slug_is_refused(slug: str) -> None:
|
|
assert not rippling.slug_ok(slug)
|
|
assert not ats.is_known_target(f"rippling:{slug}")
|
|
|
|
|
|
def test_no_slug_reaches_another_host() -> None:
|
|
for slug in ("rippling", "Prisma-Careers", "a-b_c"):
|
|
for url in (rippling.feed_url(slug), rippling.careers_url(slug),
|
|
rippling.robots_page(slug)):
|
|
assert httpx.URL(url).host in ("api.rippling.com", "ats.rippling.com")
|
|
|
|
|
|
def test_discovery_finds_the_board_slug() -> None:
|
|
page = ('<a href="https://ats.rippling.com/prisma-careers/jobs">Jobs</a>'
|
|
'<a href="https://ats.rippling.com/Acme/jobs/abc">Role</a>'
|
|
'<script>fetch("https://api.rippling.com/platform/api/ats/v1/board/beta/jobs")</script>')
|
|
assert [(h, s) for h, s, _ in boards_in(page)] == [
|
|
("rippling", "prisma-careers"), ("rippling", "Acme"), ("rippling", "beta")]
|