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

+155 -31
View File
@@ -1,7 +1,8 @@
"""ATS boards: Greenhouse, Lever, Ashby, Workable, SmartRecruiters, Recruitee, Personio.
"""ATS boards: Greenhouse, Lever, Ashby, Workable, SmartRecruiters, Recruitee, Personio,
Teamtailor.
Every one of these hosts is a company's own careers page speaking public,
unauthenticated JSON (Personio: XML) — first-party, no scraping, and a role
unauthenticated JSON (Personio, Teamtailor: XML) — first-party, no scraping, and a role
that drops off the board is *closed*, which is the cheapest staleness check
there is.
@@ -12,18 +13,25 @@ The field map and the redirect allow-list are ported from
Recruitee and Personio are new: jobhunt-hq only read Greenhouse, Lever and
Ashby, so those four are written from one real board of each host, fetched
while this file was written (2026-09-23; Workable on 2026-09-28, when the
first board with roles was seen), rather than from the Go source.
first board with roles was seen), rather than from the Go source. Teamtailor
is the same, written from live feeds on 2026-09-29.
The body cap is not a straight port — see `MAX_BYTES` below.
A target is `host:slug`, e.g. `greenhouse:databricks`, `ashby:deepl`,
`lever:acme`. Every board is fetched independently; one that fails or times
`lever:acme`, `teamtailor:acme`. Every board is fetched independently; one that fails or times
out is logged, recorded as failing under `ats:failing:<target>` (see
`ATSSource.fetch`), and skipped, and the rest continue.
Workable and SmartRecruiters page their list and state a total; every other
host answers with the whole board at once. A paged board counts as complete
only when it read as many distinct roles as the total says (see `_paged`).
A Teamtailor slug is the `acme` of acme.teamtailor.com, or, for a career site
on the company's own domain, that whole host name: `teamtailor:careers.acme.com`
(see `_teamtailor_site`).
Workable and SmartRecruiters page their list and state a total; Teamtailor
pages by offset and states none; every other host answers with the whole board
at once. A board with a total counts as complete only when it read as many
distinct roles as the total says, one without when it read up to an empty page
(see `_paged`).
"""
from __future__ import annotations
@@ -36,6 +44,7 @@ import time
import xml.etree.ElementTree as ET
from collections.abc import Callable, Iterator
from datetime import UTC, datetime
from email.utils import parsedate_to_datetime
from typing import Any
import httpx
@@ -76,7 +85,8 @@ TIMEOUTS = httpx.Timeout(10.0, read=30.0)
DEADLINE = 60.0
#: host -> (feed URL template, careers URL template). `{slug}` is filled in;
#: recruitee and personio put the slug in the hostname instead of the path.
#: recruitee and personio put the slug in the hostname instead of the path,
#: and teamtailor's `{site}` is the whole host (see `_teamtailor_site`).
_BOARDS: dict[str, tuple[str, str]] = {
"greenhouse": ("https://boards-api.greenhouse.io/v1/boards/{slug}/jobs"
"?content=true&pay_transparency=true",
@@ -94,6 +104,7 @@ _BOARDS: dict[str, tuple[str, str]] = {
"https://{slug}.recruitee.com"),
"personio": ("https://{slug}.jobs.personio.de/xml",
"https://{slug}.jobs.personio.de"),
"teamtailor": ("https://{site}/jobs.rss", "https://{site}/jobs"),
}
#: host -> the name the host gives itself: the hosts this plugin reads, in
@@ -102,13 +113,14 @@ _BOARDS: dict[str, tuple[str, str]] = {
HOSTS: dict[str, str] = {
"greenhouse": "Greenhouse", "lever": "Lever", "ashby": "Ashby",
"workable": "Workable", "smartrecruiters": "SmartRecruiters",
"recruitee": "Recruitee", "personio": "Personio",
"recruitee": "Recruitee", "personio": "Personio", "teamtailor": "Teamtailor",
}
assert set(HOSTS) == set(_BOARDS)
#: The hosts a request or a redirect may land on for a given board host — a
#: fixed API host for five of them, and the company's own subdomain for the
#: two that put the slug in the hostname. Anything else is refused, at the
#: fixed API host for five of them, the company's own subdomain for the two
#: that put the slug in the hostname, and the one site a Teamtailor slug names.
#: Anything else is refused, at the
#: first hop and at every redirect: a feed is external content, and a board
#: row must never be able to point this fetch at an internal address.
def _allowed_host(host: str, slug: str) -> Callable[[str], bool]:
@@ -128,9 +140,31 @@ def _allowed_host(host: str, slug: str) -> Callable[[str], bool]:
if host == "personio":
want = f"{slug}.jobs.personio.de"
return lambda h: h == want
if host == "teamtailor":
want = _teamtailor_site(slug)
return lambda h: h == want
return lambda h: False
#: The host a Teamtailor career site is served from: `acme` is
#: acme.teamtailor.com, and a slug with a dot is a site on the company's own
#: domain, `careers.acme.com`, taken whole (the feed path is the same on both).
#: Only a DNS name with a letter in its last label is one, so an address
#: (`127.0.0.1`, `[::1]`) or a single word never names a host the fetch could be
#: pointed at; `_get` still refuses every host but this one, redirects included.
_TEAMTAILOR_HOST = re.compile(r"^[a-z0-9-]+(\.[a-z0-9-]+)*$")
def _teamtailor_site(slug: str) -> str:
slug = slug.strip().lower()
return slug if "." in slug else f"{slug}.teamtailor.com"
def _teamtailor_slug_ok(slug: str) -> bool:
site = _teamtailor_site(slug)
return bool(_TEAMTAILOR_HOST.match(site)) and not site.rsplit(".", 1)[-1].isdigit()
def _is_web_url(url: str) -> bool:
"""A trimmed http(s) URL, or refuse — a feed is external content and a
`javascript:` or `data:` link must never reach an href. Port of
@@ -200,8 +234,8 @@ def _get(client: httpx.Client, url: str, host: str, slug: str, *,
def _parse_dt(value: Any) -> datetime | None:
"""An aware datetime from whatever a board sends: ISO-8601 with an
offset, `Z`, a bare date, epoch milliseconds, or "YYYY-MM-DD HH:MM:SS
UTC". None for anything else, which `Item` reads as "now"."""
offset, `Z`, a bare date, epoch milliseconds, "YYYY-MM-DD HH:MM:SS UTC",
or an RSS date ("Tue, 29 Sep 2026 13:36:59 +0200"). None for anything else, which `Item` reads as "now"."""
if value is None:
return None
if isinstance(value, int | float):
@@ -217,7 +251,11 @@ def _parse_dt(value: Any) -> datetime | None:
except ValueError:
match = re.match(r"^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2}:\d{2})", text)
if not match:
return None
try:
parsed = parsedate_to_datetime(text)
except (TypeError, ValueError):
return None
return parsed if parsed.utcoffset() is not None else parsed.replace(tzinfo=UTC)
parsed = datetime.fromisoformat(f"{match.group(1)}T{match.group(2)}+00:00")
return parsed if parsed.utcoffset() is not None else parsed.replace(tzinfo=UTC)
@@ -234,7 +272,7 @@ Row = dict[str, Any]
# (integers) and `currency` (ISO 4217) — the columns `upsert_role` unpacks
# `raw` into, per docs/decisions.md's "raw is transport, columns are
# storage". Only Ashby, Greenhouse, Lever, Recruitee and Personio give
# structured pay on their list endpoint; Workable and SmartRecruiters do not
# structured pay on their list endpoint; Workable, SmartRecruiters and Teamtailor do not
# (checked live, 2026-09-29), so their parsers are untouched and `row.get`
# below reads a plain '' or None for them.
@@ -684,8 +722,67 @@ def _parse_personio(body: bytes, slug: str) -> list[Row]:
return rows
#: Teamtailor's own namespace in the feed, the `tt:` of `tt:locations`.
_TT = "{https://teamtailor.com/locations}"
#: Teamtailor's `remoteStatus` -> `store._remote`'s words. `none` says nothing
#: about where the role is worked and `temporary` is remote for a spell only,
#: so both stay unknown rather than become "onsite" or "remote".
_TEAMTAILOR_REMOTE = {"fully": "remote", "hybrid": "hybrid", "onsite": "onsite"}
def _parse_teamtailor(body: bytes, slug: str) -> list[Row]:
return _teamtailor_rows(_teamtailor_items(body), slug)
def _teamtailor_items(body: bytes) -> list[ET.Element]:
"""`{site}/jobs.rss` -> `<rss><channel><item>...`, the feed every Teamtailor
career site serves (checked live on a dozen sites, 2026-09-29). A missing
`channel` is a page that is not a feed, and raises."""
channel = ET.fromstring(body).find("channel")
if channel is None:
raise ValueError("not a Teamtailor feed: no channel")
return channel.findall("item")
def _teamtailor_rows(items: list[ET.Element], slug: str) -> list[Row]:
"""One page of items. The item has the title, the job URL (on the site's
own domain), a `guid` uuid, `pubDate`, the HTML `description` in full,
`remoteStatus` (fully, hybrid, onsite, none or temporary), and, in the
`tt:` namespace, `locations` (a list: `city` and `country` each, `name` free
text), `department` and `role`, either of which may be empty. `place` joins
the distinct locations with "; ", which `country_of` reads a location at a
time. No pay is stated anywhere in the feed."""
rows = []
for item in items:
title = (item.findtext("title") or "").strip()
url = (item.findtext("link") or "").strip()
if not title or not _is_web_url(url):
continue
places: list[str] = []
for loc in item.findall(f"{_TT}locations/{_TT}location"):
city = (loc.findtext(f"{_TT}city") or loc.findtext(f"{_TT}name") or "").strip()
country = (loc.findtext(f"{_TT}country") or "").strip()
place = city if country == city else ", ".join(p for p in (city, country) if p)
if place and place not in places:
places.append(place)
rows.append({
"source_id": (item.findtext("guid") or url).strip(),
"title": title,
"location": "; ".join(places),
"url": url,
"posted": _parse_dt(item.findtext("pubDate")),
"department": ((item.findtext(f"{_TT}department") or "").strip()
or (item.findtext(f"{_TT}role") or "").strip()),
"description": html.unescape(strip_html(item.findtext("description") or "")),
"remote": _TEAMTAILOR_REMOTE.get((item.findtext("remoteStatus") or "").strip()),
"salary_text": "", # Teamtailor's feed states no pay at all
})
return rows
#: host -> parser. Every one takes the raw response body, plus the slug for
#: the two hosts whose feed does not carry the URL or the company itself.
#: the hosts whose feed does not carry the URL or the company itself.
_PARSERS: dict[str, Callable[..., list[Row]]] = {
"greenhouse": lambda body, slug: _parse_greenhouse(body),
"lever": lambda body, slug: _parse_lever(body),
@@ -694,6 +791,7 @@ _PARSERS: dict[str, Callable[..., list[Row]]] = {
"smartrecruiters": _parse_smartrecruiters,
"recruitee": lambda body, slug: _parse_recruitee(body),
"personio": _parse_personio,
"teamtailor": _parse_teamtailor,
}
@@ -825,11 +923,13 @@ def classify(department: str, title: str) -> str:
def is_known_target(target: str) -> bool:
"""`host:slug`, with `host` one of `_BOARDS` and a non-empty slug. What
"""`host:slug`, with `host` one of `_BOARDS` and a non-empty slug (for
Teamtailor one that names a host, see `_teamtailor_slug_ok`). What
the target validator refuses: `app companies add` and the pull job
both call this before touching the network."""
host, sep, slug = target.partition(":")
return bool(sep) and host in _BOARDS and bool(slug.strip())
return (bool(sep) and host in _BOARDS and bool(slug.strip())
and (host != "teamtailor" or _teamtailor_slug_ok(slug)))
def careers_url(target: str) -> str:
@@ -838,12 +938,12 @@ def careers_url(target: str) -> str:
host, _, slug = target.partition(":")
if host not in _BOARDS:
return ""
return _BOARDS[host][1].format(slug=slug)
return _BOARDS[host][1].format(slug=slug, site=_teamtailor_site(slug))
#: Pages read from one paged board at most, and the pause between two of
#: them. Workable answers ten roles a page and SmartRecruiters a hundred, so
#: the cap is 1,000 and 10,000 roles; the pause keeps Workable, which answers
#: them. Workable answers ten roles a page, SmartRecruiters a hundred and
#: Teamtailor fifty, so the cap is 1,000, 10,000 and 5,000 roles; the pause keeps Workable, which answers
#: a burst with 429, from seeing one.
MAX_PAGES = 100
PAGE_DELAY = 0.5
@@ -851,9 +951,17 @@ PAGE_DELAY = 0.5
#: SmartRecruiters' page size, which is also the most it serves per page.
SMARTRECRUITERS_PAGE = 100
#: Teamtailor's page size, asked for as `per_page`. A feed with neither
#: parameter answers with every role (73 of 73 at Shine, 2026-09-29), but says
#: nowhere that it is the whole list, so this reads by page to an empty one;
#: `per_page=200` was answered in full too, and the cursor advances by what a
#: page returned, so a smaller cap on the host's side would not skip a role.
TEAMTAILOR_PAGE = 50
#: A paged host's one page: `(client, slug, cursor)` -> the decoded page, its
#: raw results, the total it states, and the cursor of the next page (None
#: after the last). The first call gets cursor None.
#: raw results, the total it states (None for a host that states none), and the
#: cursor of the next page (None after the last). The first call gets cursor
#: None.
Page = tuple[dict[str, Any], list[dict[str, Any]], Any, Any]
@@ -873,19 +981,32 @@ def _smartrecruiters_page(client: httpx.Client, slug: str, cursor: Any) -> Page:
return data, content, data.get("totalFound"), offset + len(content) if content else None
def _teamtailor_page(client: httpx.Client, slug: str, cursor: Any) -> Page:
offset = int(cursor or 0)
url = (_BOARDS["teamtailor"][0].format(site=_teamtailor_site(slug))
+ f"?per_page={TEAMTAILOR_PAGE}&offset={offset}")
items = _teamtailor_items(_get(client, url, "teamtailor", slug))
results = [{"id": item.findtext("guid") or item.findtext("link") or ""} for item in items]
return items, results, None, offset + len(items) if items else None
#: host -> (one page, that page's rows) for the hosts that page.
_PAGED: dict[str, tuple[Callable[[httpx.Client, str, Any], Page],
Callable[[dict[str, Any], str], list[Row]]]] = {
"workable": (_workable_page, _workable_rows),
"smartrecruiters": (_smartrecruiters_page, _smartrecruiters_rows),
"teamtailor": (_teamtailor_page, _teamtailor_rows),
}
def _paged(client: httpx.Client, target: str) -> tuple[list[Row], bool]:
"""Every page of a Workable or SmartRecruiters board, `PAGE_DELAY` apart,
until the host has no next page, the stated total is reached, or
`MAX_PAGES`. Returns the rows and whether the board is complete: as many
distinct results read as the host's stated total. Counted on the raw
"""Every page of a Workable, SmartRecruiters or Teamtailor board,
`PAGE_DELAY` apart, until the host has no next page, the stated total is
reached, or `MAX_PAGES`. Returns the rows and whether the board is
complete: as many distinct results read as the host's stated total, or,
for a host that states none (Teamtailor), the read ended on an empty page
(a page with nothing new in it ends the read short of that, incomplete,
so an offset the host ignores cannot loop). Counted on the raw
results, so a row the parser drops does not make a board incomplete, and
on distinct ids, so a page that shifted under an offset and repeated a
role does not make it complete.
@@ -909,14 +1030,17 @@ def _paged(client: httpx.Client, target: str) -> tuple[list[Row], bool]:
log.warning("ats: %s: 429 on page %d; kept %d of %s, not complete",
target, page + 1, len(seen), total)
return list(rows.values()), False
before = len(seen)
seen |= {str(r.get("id") or r.get("shortcode") or "") for r in results}
for row in rows_of(data, slug):
rows.setdefault(row["source_id"], row)
if cursor is None or (isinstance(total, int) and len(seen) >= total):
if (cursor is None or (isinstance(total, int) and len(seen) >= total)
or (total is None and len(seen) == before)):
break
complete = isinstance(total, int) and len(seen) == total
complete = len(seen) == total if isinstance(total, int) else total is None and cursor is None
if not complete:
log.warning("ats: %s: read %d of %s stated; not complete", target, len(seen), total)
log.warning("ats: %s: read %d of %s stated; not complete", target, len(seen),
"an unstated total" if total is None else total)
return list(rows.values()), complete
@@ -972,7 +1096,7 @@ def failure_reason(exc: BaseException) -> str:
class ATSSource(Source):
name = "ats"
description = "Company job boards: Greenhouse, Lever, Ashby, Workable, " \
"SmartRecruiters, Recruitee, Personio."
"SmartRecruiters, Recruitee, Personio, Teamtailor."
#: The raw entries under `sources.ats.boards` are `{"url": target, "label":
#: company}` — `url` carries the `host:slug` target and `label` the
#: company name, which is how `Source.targets()`'s generic dict reading
+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: