Merge branch 'wp3-teamtailor'

This commit is contained in:
Wolf committed 2026-09-29 16:15:22 +02:00
commit d887a91af0
4 files changed
+461 -41

No files matched your search

+232 -2
View File
@@ -6,6 +6,7 @@ from __future__ import annotations
import json
import sys
from datetime import UTC, datetime
from pathlib import Path
from collections.abc import Callable, Iterator
from typing import Any
@@ -194,6 +195,120 @@ def test_personio_salary_text_states_a_monthly_rate_with_no_currency() -> None:
(None, None, "")
# Trimmed from live feeds of 2026-09-29 (career.kry.se, careers.tobii.com): the
# `tt:` namespace, an item with several locations, one whose city is a country,
# an empty department with a role, and one whose link is not a web URL.
TEAMTAILOR = """<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:tt="https://teamtailor.com/locations">
<channel>
<title>Kry</title>
<description>Job openings</description>
<link>https://career.kry.se/jobs</link>
<item>
<title>Software Engineer</title>
<description>&lt;h1&gt;About the role&lt;/h1&gt;&lt;p&gt;Build &amp;amp; run care.&lt;/p&gt;</description>
<pubDate>Wed, 23 Sep 2026 12:59:53 +0200</pubDate>
<link>https://career.kry.se/jobs/8440833-software-engineer</link>
<remoteStatus>hybrid</remoteStatus>
<guid>39ac1fca-a904-4905-b780-18c599e99b07</guid>
<company_name>Kry</company_name>
<tt:locations>
<tt:location>
<tt:name>Sverige</tt:name><tt:address/><tt:zip/>
<tt:city>Sverige</tt:city><tt:country>Sweden</tt:country>
</tt:location>
<tt:location>
<tt:name>Stockholm, Sverige</tt:name><tt:address>Torsgatan 21</tt:address>
<tt:zip>113 21</tt:zip><tt:city>Stockholm</tt:city><tt:country>Sweden</tt:country>
</tt:location>
<tt:location>
<tt:name>Stockholm, Sverige</tt:name><tt:address>Torsgatan 21</tt:address>
<tt:zip>113 21</tt:zip><tt:city>Stockholm</tt:city><tt:country>Sweden</tt:country>
</tt:location>
</tt:locations>
<tt:department>Engineering</tt:department>
<tt:role/>
</item>
<item>
<title> Läkare </title>
<description>&lt;p&gt;Träffa patienter.&lt;/p&gt;</description>
<pubDate>Fri, 31 Jul 2026 14:51:42 +0200</pubDate>
<link>https://career.kry.se/jobs/8156121-lakare</link>
<remoteStatus>fully</remoteStatus>
<guid>9787a509-ff84-400a-ad68-84e22c4cf2fb</guid>
<tt:locations>
<tt:location>
<tt:name>Sweden</tt:name><tt:address>Karlsrovägen 2D</tt:address>
<tt:zip>182 53</tt:zip><tt:city>Danderyd</tt:city><tt:country>Sweden</tt:country>
</tt:location>
</tt:locations>
<tt:department/>
<tt:role>Software Development</tt:role>
</item>
<item>
<title>Sales Lead</title>
<description></description>
<link>https://career.kry.se/jobs/8156122-sales-lead</link>
<remoteStatus>none</remoteStatus>
<guid>0a0a0a0a-ff84-400a-ad68-84e22c4cf2fb</guid>
<tt:locations/>
<tt:department>Sales</tt:department>
<tt:role/>
</item>
<item>
<title>Elsewhere</title>
<link>javascript:alert(1)</link>
<guid>bad</guid>
</item>
</channel>
</rss>
""".encode()
def test_teamtailor_reads_the_rss_feed_with_its_own_namespace() -> None:
rows = ats._parse_teamtailor(TEAMTAILOR, "kry")
# the javascript: link is refused like on the other hosts
assert [r["source_id"] for r in rows] == [
"39ac1fca-a904-4905-b780-18c599e99b07", "9787a509-ff84-400a-ad68-84e22c4cf2fb",
"0a0a0a0a-ff84-400a-ad68-84e22c4cf2fb"]
first = rows[0]
assert first["url"] == "https://career.kry.se/jobs/8440833-software-engineer"
assert first["department"] == "Engineering"
assert first["description"] == "About the role Build & run care."
assert first["posted"] == datetime(2026, 9, 23, 10, 59, 53, tzinfo=UTC)
assert first["salary_text"] == ""
def test_teamtailor_joins_the_distinct_locations_for_country_of() -> None:
from app.models import country_of
rows = ats._parse_teamtailor(TEAMTAILOR, "kry")
# "Sverige" (a city that is a country) once, Stockholm's twin once
assert rows[0]["location"] == "Sverige, Sweden; Stockholm, Sweden"
assert rows[1]["location"] == "Danderyd, Sweden"
assert rows[2]["location"] == ""
assert country_of(rows[0]["location"]) == "SE"
def test_teamtailor_maps_remote_status_and_falls_back_to_role_for_department() -> None:
rows = ats._parse_teamtailor(TEAMTAILOR, "kry")
assert [r["remote"] for r in rows] == ["hybrid", "remote", None] # none says nothing
assert rows[1]["title"] == "Läkare" # trimmed
assert rows[1]["department"] == "Software Development"
assert ats.classify(rows[1]["department"], "Sales Lead") == "sales"
def test_teamtailor_refuses_a_page_that_is_not_a_feed() -> None:
with pytest.raises(ValueError):
ats._parse_teamtailor(b"<rss version='2.0'/>", "kry")
def test_parse_dt_reads_an_rss_date_and_still_refuses_junk() -> None:
assert ats._parse_dt("Tue, 29 Sep 2026 13:36:59 +0200") == \
datetime(2026, 9, 29, 11, 36, 59, tzinfo=UTC)
assert ats._parse_dt("last tuesday") is None
# ------------------------------------------------------------ salary math
def test_yearly_amount_converts_a_monthly_range_by_12() -> None:
@@ -264,14 +379,19 @@ def test_classify_understands_a_modest_set_of_other_languages() -> None:
# ------------------------------------------------------------- allow-list
def test_is_known_target_accepts_the_seven_hosts_and_refuses_others() -> None:
def test_is_known_target_accepts_the_eight_hosts_and_refuses_others() -> None:
for host in ("greenhouse", "lever", "ashby", "workable", "smartrecruiters",
"recruitee", "personio"):
"recruitee", "personio", "teamtailor"):
assert ats.is_known_target(f"{host}:acme")
assert not ats.is_known_target("linkedin:acme")
assert not ats.is_known_target("workday:acme")
assert not ats.is_known_target("greenhouse:")
assert not ats.is_known_target("nohostnoseparator")
# a Teamtailor slug names a host: its own subdomain, or a whole domain
assert ats.is_known_target("teamtailor:careers.acme.com")
assert not ats.is_known_target("teamtailor:127.0.0.1")
assert not ats.is_known_target("teamtailor:acme.com/x")
assert not ats.is_known_target("teamtailor:acme com")
def test_allowed_host_refuses_a_foreign_host_per_board() -> None:
@@ -286,11 +406,20 @@ def test_allowed_host_refuses_a_foreign_host_per_board() -> None:
assert allow_recruitee("acme.recruitee.com")
assert not allow_recruitee("other.recruitee.com")
# teamtailor: the subdomain of a plain slug, the whole host of a dotted one
assert ats._allowed_host("teamtailor", "acme")("acme.teamtailor.com")
assert not ats._allowed_host("teamtailor", "acme")("other.teamtailor.com")
own = ats._allowed_host("teamtailor", "Careers.Acme.com")
assert own("careers.acme.com")
assert not own("acme.com") and not own("careers.acme.com.evil.example")
def test_careers_url_is_filled_per_host_and_empty_for_unknown() -> None:
assert ats.careers_url("greenhouse:acme") == "https://job-boards.greenhouse.io/acme"
assert ats.careers_url("ashby:acme") == "https://jobs.ashbyhq.com/acme"
assert ats.careers_url("recruitee:acme") == "https://acme.recruitee.com"
assert ats.careers_url("teamtailor:acme") == "https://acme.teamtailor.com/jobs"
assert ats.careers_url("teamtailor:careers.acme.com") == "https://careers.acme.com/jobs"
assert ats.careers_url("workday:acme") == ""
@@ -517,6 +646,107 @@ def test_a_429_on_the_first_page_is_a_failure(
ats._fetch_rows(object(), "workable:exotec") # type: ignore[arg-type]
def _feed(guids: list[str]) -> bytes:
"""A Teamtailor feed of `guids`, one role each."""
items = "".join(
f"<item><title>Role {g}</title><link>https://careers.acme.com/jobs/{g}</link>"
f"<guid>{g}</guid></item>" for g in guids)
return ('<rss xmlns:tt="https://teamtailor.com/locations"><channel>'
f"{items}</channel></rss>").encode()
def _teamtailor_web(monkeypatch: pytest.MonkeyPatch, guids: list[str],
page: int = 2) -> list[str]:
"""`_get` answering from `guids` by `offset` and `per_page`, as a
Teamtailor site does, returning the URLs it was asked."""
urls: list[str] = []
def fake_get(client, url, host, slug, *, method="GET", payload=None):
urls.append(url)
query = dict(httpx.URL(url).params)
start, size = int(query["offset"]), min(int(query["per_page"]), page)
return _feed(guids[start:start + size])
monkeypatch.setattr(ats, "_get", fake_get)
return urls
def test_teamtailor_pages_by_offset_and_is_complete_on_an_empty_page(
monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None:
"""The host caps a page below what was asked; the offset advances by what
came back, and the read ends on the empty page after the last role."""
urls = _teamtailor_web(monkeypatch, ["a", "b", "c", "d", "e"])
rows, complete = ats._fetch_rows(object(), "teamtailor:careers.acme.com") # type: ignore[arg-type]
base = "https://careers.acme.com/jobs.rss?per_page=50"
assert urls == [f"{base}&offset=0", f"{base}&offset=2", f"{base}&offset=4",
f"{base}&offset=5"]
assert [r["source_id"] for r in rows] == ["a", "b", "c", "d", "e"]
assert complete
def test_a_teamtailor_slug_without_a_dot_is_a_teamtailor_subdomain(
monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None:
urls = _teamtailor_web(monkeypatch, ["a"])
ats._fetch_rows(object(), "teamtailor:acme") # type: ignore[arg-type]
assert urls[0].startswith("https://acme.teamtailor.com/jobs.rss?")
def test_a_board_with_no_roles_is_complete_at_zero(
monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None:
_teamtailor_web(monkeypatch, [])
assert ats._fetch_rows(object(), "teamtailor:acme") == ([], True) # type: ignore[arg-type]
def test_a_teamtailor_host_that_ignores_the_offset_is_incomplete(
monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None:
"""The same page again: nothing new, so the read stops rather than loops."""
calls: list[str] = []
def fake_get(client, url, host, slug, *, method="GET", payload=None):
calls.append(url)
return _feed(["a", "b"])
monkeypatch.setattr(ats, "_get", fake_get)
rows, complete = ats._fetch_rows(object(), "teamtailor:acme") # type: ignore[arg-type]
assert (len(calls), len(rows), complete) == (2, 2, False)
def test_the_page_cap_leaves_a_teamtailor_board_incomplete(
monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None:
_teamtailor_web(monkeypatch, [str(n) for n in range(10)])
monkeypatch.setattr(ats, "MAX_PAGES", 2)
rows, complete = ats._fetch_rows(object(), "teamtailor:acme") # type: ignore[arg-type]
assert (len(rows), complete) == (4, False)
def test_a_teamtailor_429_after_the_first_page_is_incomplete(
monkeypatch: pytest.MonkeyPatch, no_delay: None) -> None:
def fake_get(client, url, host, slug, *, method="GET", payload=None):
if "offset=0" not in url:
raise _status(429)
return _feed(["a", "b"])
monkeypatch.setattr(ats, "_get", fake_get)
rows, complete = ats._fetch_rows(object(), "teamtailor:acme") # type: ignore[arg-type]
assert ([r["source_id"] for r in rows], complete) == (["a", "b"], False)
def test_teamtailor_is_read_through_the_streamed_get_and_a_redirect_elsewhere_is_refused(
no_delay: None) -> None:
def handler(request: httpx.Request) -> httpx.Response:
if request.url.host == "moved.acme.com":
return httpx.Response(302, headers={"location": "https://evil.example/jobs.rss"})
assert request.url.path == "/jobs.rss"
return httpx.Response(200, content=_feed(["a"] if request.url.params["offset"] == "0" else []))
with _client(handler) as client:
rows, complete = ats._fetch_rows(client, "teamtailor:careers.acme.com")
assert ([r["source_id"] for r in rows], complete) == (["a"], True)
with pytest.raises(ats._Refused):
ats._fetch_rows(client, "teamtailor:moved.acme.com")
# -------------------------------------------------------- failing boards
def _source(monkeypatch: pytest.MonkeyPatch, answer: object) -> ats.ATSSource:
+43 -3
View File
@@ -160,7 +160,7 @@ def test_a_readable_board_on_a_later_page_still_beats_an_unreadable_host() -> No
assert site.probed == []
def test_an_unreadable_hosts_slug_is_kept_when_a_later_link_names_it() -> None:
def test_a_teamtailor_link_is_a_board_even_after_the_cdn_named_it_first() -> None:
"""The CDN names teamtailor before any link does; the slug comes from the
first link that carries one, the acme of acme.teamtailor.com."""
site = Site({
@@ -168,9 +168,49 @@ def test_an_unreadable_hosts_slug_is_kept_when_a_later_link_names_it() -> None:
"https://acme.com/careers": '<a href="https://acme-jobs.teamtailor.com/jobs">Jobs</a>',
})
found = run(site)
assert (found.ats, found.ats_slug, found.board) == ("teamtailor", "acme-jobs", "")
assert (found.ats, found.ats_slug, found.board) == ("teamtailor", "acme-jobs",
"teamtailor:acme-jobs")
assert found.readable
assert found.evidence == "https://acme-jobs.teamtailor.com"
assert found.careers_url == "https://acme.com/"
assert found.careers_url == "https://acme.com/careers"
def test_a_teamtailor_site_on_its_own_domain_is_read_off_its_host() -> None:
"""Only the CDN is named, so the site's host is the slug, once that host
serves the feed."""
site = Site({
"https://acme.com/": '<a href="https://careers.acme.com/">Careers</a>',
"https://careers.acme.com/": '<script src="https://cdn.teamtailor.com/x.js"></script>',
"https://careers.acme.com/jobs.rss":
'<rss xmlns:tt="https://teamtailor.com/locations"><channel/></rss>',
})
found = run(site)
assert found == Discovery(board="teamtailor:careers.acme.com", ats="teamtailor",
ats_slug="careers.acme.com",
careers_url="https://careers.acme.com/",
evidence="https://careers.acme.com/jobs.rss")
assert site.probed == []
def test_a_page_that_only_loads_the_cdn_is_not_a_board_without_the_feed() -> None:
site = Site({"https://acme.com/": '<script src="https://cdn.teamtailor.com/x.js"></script>'})
found = run(site)
assert (found.ats, found.ats_slug, found.board) == ("teamtailor", "", "")
assert not found.readable
assert "https://acme.com/jobs.rss" in site.fetched
def test_the_admin_app_and_cdn_hosts_are_no_teamtailor_slug() -> None:
page = '<a href="https://app.teamtailor.com/x">a</a><img src="https://cdn.teamtailor.com/y">'
assert [(h, s) for h, s, _ in boards_in(page)] == [("teamtailor", "")]
def test_a_teamtailor_board_is_found_by_its_slug_probe() -> None:
site = Site({"https://acme.com/": "<p>a script draws the jobs</p>"},
boards={("teamtailor", "acme")})
found = run(site)
assert found.board == "teamtailor:acme"
assert found.evidence == "https://acme.teamtailor.com/jobs.rss"
def test_slug_probes_find_a_board_the_pages_never_link() -> None: