Read Teamtailor career sites from their jobs.rss feed, paged by offset

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Sonnet 5.5 committed 2026-09-29 16:14:41 +02:00
1 parent b6afe24eaa
commit 50edf0eeeb
2 files changed
+387 -33

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: