Files
jobboard/tests/test_ats_rippling.py
T
WolfandClaude Opus 5.5 c497fe965d Keep a description's headings, bullets and paragraphs, and draw them in the reader
The readers flattened a posting's HTML into one line with strip_html, so
sections and bullets ran together. _shared.html_text gives a line per
paragraph, '• ' before a list item and '## ' before a heading; every
reader's description goes through it, sections read per role get their
own headings, and the reader pane draws the lines as h3, ul and p.
Excerpts leave the marks out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 21:40:12 +02:00

211 lines
9.6 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_a_remote_place_is_flagged_and_the_role_states_no_remote() -> None:
by_id = {r["source_id"][:8]: r for r in rippling.parse(BOARD, "rippling")}
assert [p["remote"] for p in by_id["46b4af52"]["places"]] == [True]
assert [p["remote"] for p in by_id["75ad50c6"]["places"]] == [None] # an office label
assert all("remote" not in r for r in by_id.values()) # prep derives it from the places
def test_prisma_board_reads_two_roles() -> None:
rows = rippling.parse(PRISMA, "prisma-careers")
assert [(r["title"], r["department"], r["location"]) for r in rows] == [
("General Applications: Engineering", "Engineering", "Remote (Germany)"),
("General Applications: Product", "Product", "Remote (Germany)")]
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-detail.json").read_bytes(), asked),
"rippling", row)
assert asked == [f"https://api.rippling.com/platform/api/ats/v1/board/rippling/jobs/{DIRECTOR}"]
assert found["description"].startswith("## About The Role\n")
assert "<" not in found["description"]
assert found["location"] == "San Francisco, CA; Seattle, WA; New York, NY"
assert [p["text"] for p in found["places"]] == ["San Francisco, CA", "Seattle, WA", "New York, NY"]
assert found["employment"] == "SALARIED_FT" # employmentType.label
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-detail-2.json").read_bytes()),
"prisma-careers", {"source_id": "x"})
assert found["description"].startswith("## What is it like to work at Prisma?\n")
assert found["location"] == "Remote (Germany)"
assert found["places"] == [{"text": "Remote (Germany)", "remote": True}]
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 &amp; 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]
# ------------------------------------------------------- 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() -> None:
assert rippling.feed_url("rippling") == FEED
assert rippling.careers_url("prisma-careers") == "https://ats.rippling.com/prisma-careers/jobs"
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)):
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")]
def test_a_role_at_several_places_keeps_each_once() -> None:
rows = {r["source_id"]: r for r in rippling.parse(BOARD, "rippling")}
director = rows[DIRECTOR]
assert [p["text"] for p in director["places"]] == [
"San Francisco, CA", "Seattle, WA", "New York, NY"]
assert director["location"] == "San Francisco, CA; Seattle, WA; New York, NY"
remote = next(r for r in rows.values() if r["places"] == [
{"text": "Remote (United States)", "remote": True}])
assert remote["places"][0]["remote"] is True