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>
190 lines
8.4 KiB
Python
190 lines
8.4 KiB
Python
"""The BambooHR host module against Configit's saved listing and two saved
|
|
role pages. No network."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from datetime import UTC, datetime
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from app.jobs import discover # noqa: E402
|
|
from plugins import ats, readers # noqa: E402
|
|
from plugins.readers import Ask, bamboohr # noqa: E402
|
|
|
|
FIXTURES = ROOT / "tests" / "fixtures" / "ats"
|
|
|
|
|
|
def _read(name: str) -> bytes:
|
|
return (FIXTURES / name).read_bytes()
|
|
|
|
|
|
def _get_of(answers: dict[str, bytes | Exception], asked: list[tuple[str, Any]]) -> Any:
|
|
def get(url: str, *, method: str = "GET", payload: Any = None,
|
|
headers: dict[str, str] | None = None) -> bytes:
|
|
asked.append((url, headers))
|
|
answer = answers[url]
|
|
if isinstance(answer, Exception):
|
|
raise answer
|
|
return answer
|
|
return get
|
|
|
|
|
|
def test_a_listing_becomes_rows() -> None:
|
|
rows = bamboohr.parse(_read("bamboohr.json"), "configit")
|
|
assert [r["source_id"] for r in rows] == ["26", "37"]
|
|
# The standing invitation to apply without a role is a role like any other.
|
|
assert rows[0]["title"] == "Unsolicited application - All Configit locations"
|
|
second = rows[1]
|
|
assert second["title"] == "Demand Generation Specialist - 12-Month Maternity Cover"
|
|
assert second["url"] == "https://configit.bamboohr.com/careers/37"
|
|
assert second["department"] == "Marketing" and rows[0]["department"] == ""
|
|
assert second["location"] == "København Ø"
|
|
assert second["remote"] == "2"
|
|
assert (second["posted"], second["description"], second["salary_text"]) == (None, "", "")
|
|
|
|
|
|
@pytest.mark.parametrize(("flag", "kind", "remote"), [
|
|
(True, "0", True), (None, "0", "0"), (None, "1", "1"), (None, "2", "2"),
|
|
(None, None, None), (False, "7", "7")])
|
|
def test_remote_is_the_flag_then_the_location_type(
|
|
flag: bool | None, kind: str | None, remote: bool | str | None) -> None:
|
|
body = json.loads(_read("bamboohr.json"))
|
|
body["result"][0] |= {"isRemote": flag, "locationType": kind}
|
|
assert bamboohr.parse(json.dumps(body).encode(), "configit")[0]["remote"] == remote
|
|
|
|
|
|
def test_the_location_reads_the_state_and_the_ats_location_too() -> None:
|
|
body = json.loads(_read("bamboohr.json"))
|
|
body["result"][0]["location"] = {"city": "Austin", "state": "Texas"}
|
|
body["result"][1]["location"] = {"city": None, "state": None}
|
|
body["result"][1]["atsLocation"] = {"city": "Lyon", "state": None, "country": "France"}
|
|
rows = bamboohr.parse(json.dumps(body).encode(), "configit")
|
|
assert [r["location"] for r in rows] == ["Austin, Texas", "Lyon, France"]
|
|
|
|
|
|
def test_a_list_shorter_than_its_count_is_refused_not_read_as_the_board() -> None:
|
|
body = json.loads(_read("bamboohr.json"))
|
|
body["meta"]["totalCount"] = 3
|
|
with pytest.raises(ValueError, match="2 of 3"):
|
|
bamboohr.parse(json.dumps(body).encode(), "configit")
|
|
|
|
|
|
def test_a_page_that_is_not_a_listing_raises_and_an_empty_board_is_no_rows() -> None:
|
|
assert bamboohr.parse(b'{"meta": {"totalCount": 0}, "result": []}', "configit") == []
|
|
for body in (b"<html></html>", b"[]", b'{"result": null}'):
|
|
with pytest.raises(ValueError):
|
|
bamboohr.parse(body, "configit")
|
|
|
|
|
|
def test_a_role_without_a_title_or_an_id_is_left_out() -> None:
|
|
body = json.loads(_read("bamboohr.json"))
|
|
body["result"][0]["jobOpeningName"] = " "
|
|
body["result"][1]["id"] = None
|
|
assert bamboohr.parse(json.dumps(body).encode(), "configit") == []
|
|
|
|
|
|
def test_detail_reads_the_text_the_date_and_the_country() -> None:
|
|
row = bamboohr.parse(_read("bamboohr.json"), "configit")[1]
|
|
asked: list[tuple[str, Any]] = []
|
|
url = "https://configit.bamboohr.com/careers/37/detail"
|
|
found = bamboohr.detail(_get_of({url: _read("bamboohr-detail-37.json")}, asked),
|
|
"configit", row)
|
|
assert asked == [(url, {"Accept": "application/json"})]
|
|
assert set(found) <= set(ats.DETAIL_FIELDS) | {"places"}
|
|
assert found["posted"] == datetime(2026, 9, 23, tzinfo=UTC)
|
|
assert found["location"] == "København Ø, Denmark"
|
|
assert found["places"] == [{"text": "København Ø, Denmark", "remote": None}]
|
|
assert found["remote"] == "2"
|
|
text = found["description"]
|
|
assert text.startswith("Our Global Marketing Team is looking for")
|
|
assert "Skills & Experience" in text and "&" not in text and "<" not in text
|
|
|
|
|
|
def test_detail_of_the_standing_invitation() -> None:
|
|
row = bamboohr.parse(_read("bamboohr.json"), "configit")[0]
|
|
url = "https://configit.bamboohr.com/careers/26/detail"
|
|
found = bamboohr.detail(_get_of({url: _read("bamboohr-detail-26.json")}, []), "configit", row)
|
|
assert found["posted"] == datetime(2025, 10, 10, tzinfo=UTC)
|
|
assert found["description"].startswith("Hi,\nIf there is currently no vacant position")
|
|
assert "UK (remote)" in found["description"]
|
|
|
|
|
|
def test_detail_refuses_an_answer_that_is_not_a_role() -> None:
|
|
url = "https://configit.bamboohr.com/careers/37/detail"
|
|
row = {"source_id": "37"}
|
|
for body in (b"<html></html>", b'{"result": {}}', b"[]"):
|
|
with pytest.raises(ValueError):
|
|
bamboohr.detail(_get_of({url: body}, []), "configit", row)
|
|
|
|
|
|
def test_the_board_and_its_details_are_read_with_the_json_accept_on_the_detail() -> None:
|
|
base = "https://configit.bamboohr.com/careers"
|
|
asked: list[tuple[str, Any]] = []
|
|
answers: dict[str, bytes | Exception] = {
|
|
f"{base}/list": _read("bamboohr.json"),
|
|
f"{base}/37/detail": _read("bamboohr-detail-37.json")}
|
|
get = _get_of(answers, asked)
|
|
rows = bamboohr.parse(get(bamboohr.feed_url("configit", Ask())), "configit")
|
|
assert len(rows) == 2
|
|
found = bamboohr.detail(get, "configit", rows[1])
|
|
assert [url for url, _ in asked] == [f"{base}/list", f"{base}/37/detail"]
|
|
assert asked[1][1] == {"Accept": "application/json"}
|
|
assert found["location"] == "København Ø, Denmark"
|
|
assert found["posted"] == datetime(2026, 9, 23, tzinfo=UTC)
|
|
|
|
|
|
def test_the_role_states_one_place_and_the_employment() -> None:
|
|
rows = bamboohr.parse(_read("bamboohr.json"), "configit")
|
|
assert rows[1]["places"] == [{"text": "København Ø", "remote": None}]
|
|
assert rows[1]["employment"] == "Full-Time"
|
|
body = json.loads(_read("bamboohr.json"))
|
|
body["result"][0] |= {"employmentStatusLabel": "Seasonal", "location": {"city": None}}
|
|
first = bamboohr.parse(json.dumps(body).encode(), "configit")[0]
|
|
assert first["places"] == [] and first["employment"] == "Seasonal"
|
|
|
|
|
|
def test_it_declares_what_it_reads() -> None:
|
|
reads = bamboohr.READS
|
|
assert (reads.listing, reads.text, reads.places, reads.fields.posted) == (
|
|
"whole", "detail", "one", "trusted")
|
|
assert reads.robots.startswith("read: robots.txt allows /careers")
|
|
|
|
|
|
def test_the_slug_the_urls_and_the_allow_list() -> None:
|
|
assert bamboohr.slug_ok("configit") and bamboohr.slug_ok("Configit")
|
|
assert bamboohr.careers_url("configit") == "https://configit.bamboohr.com/careers"
|
|
assert bamboohr.feed_url("Configit", Ask()) == "https://configit.bamboohr.com/careers/list"
|
|
allow = bamboohr.allowed("Configit")
|
|
assert allow("configit.bamboohr.com") and allow("CONFIGIT.bamboohr.com")
|
|
assert not allow("bamboohr.com") and not allow("other.bamboohr.com")
|
|
assert not allow("configit.bamboohr.com.evil.example") and not allow("localhost")
|
|
assert readers.HOSTS["bamboohr"] is bamboohr and ats.HOSTS["bamboohr"] == "BambooHR"
|
|
|
|
|
|
@pytest.mark.parametrize("slug", [
|
|
"", "a@b", "a#b", "a?b", "..", "a/b", "a%2fb", "a:443", "a b", " a", "a\n", "a\r\n",
|
|
"a.b", "127.0.0.1", "[::1]", "a_b", "2130706433.evil"])
|
|
def test_a_hostile_slug_is_refused(slug: str) -> None:
|
|
assert not bamboohr.slug_ok(slug)
|
|
assert not ats.is_known_target(f"bamboohr:{slug}")
|
|
|
|
|
|
def test_a_local_word_as_a_slug_only_reaches_bamboohrs_own_host() -> None:
|
|
allow = bamboohr.allowed("localhost")
|
|
assert allow("localhost.bamboohr.com") and not allow("localhost")
|
|
|
|
|
|
def test_discovery_finds_the_subdomain_and_not_bamboohrs_own_hosts() -> None:
|
|
page = ('<script src="https://Configit.bamboohr.com/js/embed.js"></script>'
|
|
'<a href="https://www.bamboohr.com/">x</a><a href="https://app.bamboohr.com/x">y</a>'
|
|
'<a href="https://resources.bamboohr.com/y">z</a>')
|
|
assert [(h, s) for h, s, _ in discover.boards_in(page)] == [("bamboohr", "configit")]
|