Files
jobboard/tests/test_ats_successfactors.py

589 lines
28 KiB
Python

"""The SuccessFactors host: `plugins/readers/successfactors.py` against saved
career-site pages, and against written ones through a sweep and a pull with
its settle. No network. The fixtures are trimmed pages of Vestas and
SAP (table layout), Demant and Scania (tile layout), Teradyne (a shared site
with a path prefix), and the job pages of Vestas (`addressCountry`),
Systematic (`streetAddress`) and Novo Nordisk (no microdata)."""
from __future__ import annotations
import json
import sys
from datetime import UTC, datetime
from pathlib import Path
from typing import Any, ClassVar
import httpx
import pytest
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from pipeline import Tally # noqa: E402
from app.jobs import pull # noqa: E402
from app.jobs.discover import boards_in # noqa: E402
from app.storage import Store # noqa: E402
from plugins import ats, readers # noqa: E402
from plugins.readers import successfactors # noqa: E402
FIXTURES = ROOT / "tests" / "fixtures" / "ats"
class FakeConfig:
sources: ClassVar[dict[str, object]] = {}
searches: ClassVar[list[object]] = []
def _pull(store: Store) -> dict[str, Any]:
"""One pull of every board, batches and settle, as `test_sweep_strikes`."""
results = [pull.run_batch(FakeConfig(), store, **batch) # type: ignore[arg-type]
for batch in pull._boards(FakeConfig(), store)] # type: ignore[arg-type]
return pull.close_boards(FakeConfig(), store, Tally(results=tuple(results))) # type: ignore[arg-type]
def _read(name: str) -> str:
return (FIXTURES / name).read_text(encoding="utf-8")
# ------------------------------------------------------------------- rows
def test_the_table_layout_gives_title_location_date_and_department() -> None:
rows = successfactors.rows(_read("successfactors-table.html"), "careers.vestas.com")
assert len(rows) == 5
first = rows[0]
assert first["source_id"] == "1431772533"
assert first["title"] == "Director, Service Commercial"
# The site's "City, Region, CC, zip" becomes the country's name, so that
# `country_of` reads it (a bare "DE" would be Delaware), and the postcode goes.
assert first["location"] == "Seoul, Seoul-teukpyolsi, South Korea"
assert first["url"] == ("https://careers.vestas.com/job/"
"Seoul-Director%2C-Service-Commercial-Seou-04323/1431772533/")
assert first["department"] == "Commercial"
assert first["posted"] == datetime(2026, 9, 29, tzinfo=UTC) # "29 Sept 2026"
assert first["description"] == "" and first["salary_text"] == ""
assert first["remote"] is None
def test_a_row_is_listed_once_though_the_table_links_it_twice() -> None:
"""The title link is in the row twice, once for the phone."""
text = _read("successfactors-table.html")
assert text.count("/1431772533/") >= 2
rows = successfactors.rows(text, "careers.vestas.com")
assert len({r["source_id"] for r in rows}) == len(rows) == 5
def test_a_table_without_a_date_or_department_column_still_reads() -> None:
"""SAP's own site: a title and a location, and an apostrophe in the link
which the page writes as an entity."""
rows = successfactors.rows(_read("successfactors-table-nodate.html"), "careers.sap.com")
assert len(rows) == 4
assert all(r["posted"] is None and r["department"] == "" for r in rows)
assert rows[0]["location"] == "Budapest, Hungary"
assert rows[1]["url"].startswith("https://careers.sap.com/job/'s-Hertogenbosch-HR-")
assert rows[1]["source_id"] == "1401271733"
def test_the_tile_layout_gives_the_city_and_the_country_of_its_own_fields() -> None:
"""Demant's tiles have a "Location" that is the city and a "Country" that is
its name; the job link carries a brand segment."""
rows = successfactors.rows(_read("successfactors-tile.html"), "careers.demant.com")
assert len(rows) == 5
first = rows[0]
assert first["source_id"] == "1431925433"
assert first["title"] == "Regulatory Affairs Specialist"
assert first["location"] == "Szczecin, Poland"
assert first["posted"] == datetime(2026, 9, 29, tzinfo=UTC)
assert first["url"].startswith("https://careers.demant.com/DemantPoland/job/Szczecin-")
assert first["department"] == "" # "Brand" is not a department
def test_a_tile_location_that_ends_in_a_country_code_is_read_with_its_name() -> None:
rows = successfactors.rows(_read("successfactors-tile-scania.html"), "jobs.scania.com")
assert len(rows) == 3
assert rows[0]["location"] == "Eichelbergstr. 4, 09212 Limbac, Germany"
assert rows[1]["location"] == "Tonalá, JAL, Mexico"
assert rows[1]["department"] == "Parts and Service" # the `department` field
assert rows[1]["posted"] == datetime(2026, 9, 29, tzinfo=UTC) # "Sep 29, 2026"
@pytest.mark.parametrize(("text", "want"), [
("29 Sept 2026", datetime(2026, 9, 29, tzinfo=UTC)),
("5 Jan 2026", datetime(2026, 1, 5, tzinfo=UTC)),
("Sep 29, 2026", datetime(2026, 9, 29, tzinfo=UTC)),
("2026/09/29", datetime(2026, 9, 29, tzinfo=UTC)),
("29.09.2026", datetime(2026, 9, 29, tzinfo=UTC)),
("09/29/2026", None), # day or month first is not guessed
("31 Foo 2026", None),
("", None),
])
def test_a_listing_date_is_read_as_the_site_writes_it(text: str, want: datetime | None) -> None:
assert successfactors._date(text) == want
@pytest.mark.parametrize(("text", "want"), [
("Smørum, DK, 2765", "Smørum, Denmark"),
("Boston, MA, US, 02110", "Boston, MA, United States"),
("Boston, MA, US", "Boston, MA, United States"),
("Haag, AT, 4680", "Haag, Austria"),
("Accra, GH, KA DTD 200", "Accra, Ghana"),
("Angers, FR", "Angers, France"),
("Kraków", "Kraków"),
("Paris, France", "Paris, France"),
("Xyz, ZZ, 1", "Xyz, ZZ, 1"), # not a country code: as written
])
def test_a_location_ends_in_the_countrys_name(text: str, want: str) -> None:
assert successfactors._place(text) == want
def test_a_link_off_the_site_is_not_a_role() -> None:
"""A title link is taken as written, and one that names another host is
dropped."""
text = _read("successfactors-tile.html").replace(
'href="/DemantPoland/job/Szczecin-Regulatory-Affairs-Specialist-zach-71-612/1431925433/"',
'href="https://elsewhere.example/job/x/1431925433/"')
rows = successfactors.rows(text, "careers.demant.com")
assert "1431925433" not in {r["source_id"] for r in rows}
assert len(rows) == 4
same = text.replace("https://elsewhere.example/", "https://careers.demant.com/")
assert "1431925433" in {r["source_id"] for r in successfactors.rows(same, "careers.demant.com")}
# -------------------------------------------------------------- path prefix
def test_a_prefix_keeps_the_roles_under_it_though_the_site_lists_others() -> None:
"""A site that does not scope on the server: the page lists Teradyne's roles
of several brands, and `jobs.teradyne.com/MiR` reads the MiR ones."""
text = _read("successfactors-shared.html")
everything = successfactors.rows(text, "jobs.teradyne.com")
assert len(everything) == 6
mir = successfactors.rows(text, "jobs.teradyne.com/MiR")
assert 0 < len(mir) < len(everything)
assert all(r["url"].startswith("https://jobs.teradyne.com/MiR/job/") for r in mir)
def test_a_scoped_site_lists_only_the_brand_and_states_its_total() -> None:
"""`/Universal-Robots/search/` answers 30 of Teradyne's 486 on the server."""
text = _read("successfactors-prefix.html")
rows = successfactors.rows(text, "jobs.teradyne.com/Universal-Robots")
assert len(rows) == 4
assert successfactors._total(text) == 30
assert rows[0]["location"] == "Bangalore, India"
assert rows[0]["department"] == "Information Technology"
# ------------------------------------------------------------------- paging
def _table_page(ids: list[int], total: int, prefix: str = "") -> str:
body = "".join(
f'<tr class="data-row"><td class="colTitle"><span class="jobTitle hidden-phone">'
f'<a href="{prefix}/job/City-Role-{i}/{i}/" class="jobTitle-link">Role {i}</a></span></td>'
f'<td class="colLocation"><span class="jobLocation">City, DK, 2100</span></td>'
f'<td class="colDate"><span class="jobDate">29 Sept 2026</span></td></tr>' for i in ids)
return (f'<span class="paginationLabel">Results <b>1 to {len(ids)}</b> of <b>{total}</b></span>'
f'<table id="searchresults"><tbody>{body}</tbody></table>')
def _tile_page(ids: list[int], total: int, prefix: str = "") -> str:
body = "".join(
f'<li class="job-tile job-id-{i}" data-url="{prefix}/job/City-Role-{i}/{i}/">'
f'<a class="jobTitle-link" href="{prefix}/job/City-Role-{i}/{i}/">Role {i}</a>'
f'<span id="job-{i}-desktop-section-date-label">Date</span>'
f'<div id="job-{i}-desktop-section-date-value">Sep 29, 2026</div>'
f'<span id="job-{i}-desktop-section-location-label">Location</span>'
f'<div id="job-{i}-desktop-section-location-value">City, DK, 2100</div></li>' for i in ids)
return (f'<span id="tile-search-results-label">Showing 1 to {len(ids)} of {total} Jobs</span>'
f'<ul id="job-tile-list">{body}</ul>')
def _site(monkeypatch: pytest.MonkeyPatch, roles: int, size: int, layout: Any = _table_page,
prefix: str = "", total: int | None = None) -> list[str]:
"""`ats._get` answering a career site's search by `startrow`, `size` roles
a page, as the site does; returns the URLs asked. `total` is what the
site states, `roles` what it has."""
ids = [1_000_000_000 + n for n in range(roles)]
asked: list[str] = []
def fake_get(client, url, host, slug, *, method="GET", payload=None, headers=None,
www_twin=False):
asked.append(url)
start = int(dict(httpx.URL(url).params)["startrow"])
return layout(ids[start:start + size], roles if total is None else total,
prefix).encode()
monkeypatch.setattr(ats, "_get", fake_get)
monkeypatch.setattr(ats, "PAGE_DELAY", 0)
return asked
@pytest.mark.parametrize("layout", [_table_page, _tile_page])
@pytest.mark.parametrize("size", [10, 15, 25, 100])
def test_the_page_size_is_learnt_from_the_rows_a_page_returned(
monkeypatch: pytest.MonkeyPatch, layout: Any, size: int) -> None:
asked = _site(monkeypatch, 105, size, layout)
rows, complete = ats._fetch_rows(object(), "successfactors:careers.acme.com") # type: ignore[arg-type]
starts = [int(u.rsplit("=", 1)[1]) for u in asked]
assert starts == list(range(0, 105, size))
assert asked[0] == "https://careers.acme.com/search/?q=&locationsearch=&startrow=0"
assert len(rows) == 105 and complete
assert rows[0]["source_id"] == "1000000000" and rows[0]["posted"] is not None
@pytest.mark.parametrize("layout", [_table_page, _tile_page])
def test_the_stated_total_ends_the_read_in_both_layouts(
monkeypatch: pytest.MonkeyPatch, layout: Any) -> None:
"""A site that answers a page past the end (Vestas did, at 670 of 661)
is not asked: the read stops at the total."""
asked = _site(monkeypatch, 20, 10, layout)
rows, complete = ats._fetch_rows(object(), "successfactors:careers.acme.com") # type: ignore[arg-type]
assert len(asked) == 2 and len(rows) == 20 and complete
@pytest.mark.parametrize(("name", "total"), [
("successfactors-table.html", 668),
("successfactors-table-nodate.html", 813),
("successfactors-tile.html", 307),
("successfactors-tile-scania.html", 763),
])
def test_the_total_is_read_from_a_saved_page_in_both_layouts(name: str, total: int) -> None:
assert successfactors._total(_read(name)) == total
def test_a_saved_page_gives_its_step_its_total_and_the_next_cursor() -> None:
text = _read("successfactors-table.html")
decoded, results, total, cursor = successfactors.page(
lambda url, **kw: text.encode(), "careers.vestas.com", None)
assert decoded == text
assert [r["id"] for r in results][:2] == ["1431772533", "1432067433"] and len(results) == 5
assert total == 668
assert cursor == (5, "1431772533") # the next start row is the rows returned
def test_a_total_larger_than_what_the_site_lists_is_incomplete(
monkeypatch: pytest.MonkeyPatch) -> None:
asked = _site(monkeypatch, 15, 10, total=40)
rows, complete = ats._fetch_rows(object(), "successfactors:careers.acme.com") # type: ignore[arg-type]
assert len(rows) == 15 and not complete
assert len(asked) == 3 # read on, after a short page, to an empty one
def test_a_site_that_ignores_startrow_does_not_loop(monkeypatch: pytest.MonkeyPatch) -> None:
asked: list[str] = []
def fake_get(client, url, host, slug, **kw):
asked.append(url)
return _table_page([1_000_000_001, 1_000_000_002], 50).encode()
monkeypatch.setattr(ats, "_get", fake_get)
monkeypatch.setattr(ats, "PAGE_DELAY", 0)
rows, complete = ats._fetch_rows(object(), "successfactors:careers.acme.com") # type: ignore[arg-type]
assert len(rows) == 2 and not complete
assert len(asked) == 2
def _untotalled(ids: list[int]) -> str:
"""A table page that states no total."""
return _table_page(ids, 0).split("</span>", 1)[1]
def test_the_repeated_page_hands_back_a_cursor_with_no_results() -> None:
text = _untotalled([1_000_000_001, 1_000_000_002])
_decoded, results, total, cursor = successfactors.page(
lambda url, **kw: text.encode(), "careers.acme.com", [2, "1000000001"])
assert (results, total, cursor) == ([], None, (2, "1000000001"))
def test_a_site_that_ignores_startrow_and_states_no_total_closes_nothing(
monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
"""The repeated first page used to end the read with no cursor, which a
site that states no total made complete, and the settle closed every
role past the first page."""
store = Store(tmp_path / "roledesk.db")
store.add_subscription("ats", "successfactors:careers.acme.com", label="Acme",
company="Acme", board="successfactors")
ids = [1_000_000_000 + n for n in range(4)]
site = {"ignores_startrow": False}
def fake_get(client, url, host, slug, **kw):
start = 0 if site["ignores_startrow"] else int(dict(httpx.URL(url).params)["startrow"])
return _untotalled(ids[start:start + 2]).encode()
monkeypatch.setattr(ats, "_get", fake_get)
monkeypatch.setattr(ats, "PAGE_DELAY", 0)
_pull(store)
assert store.state["ats:complete:successfactors:careers.acme.com"] == "1"
assert len(store.roles()) == 4
site["ignores_startrow"] = True
result = _pull(store)
assert store.state["ats:complete:successfactors:careers.acme.com"] == ""
assert (result["incomplete"], result["closed"], len(store.roles())) == (1, 0, 4)
def test_a_site_over_the_page_cap_is_swept_from_its_cursor_as_json_gives_it_back(
monkeypatch: pytest.MonkeyPatch) -> None:
"""The cursor `(start row, first id)` is a tuple, kept in state as a
list. The sweep is kept, and the next pull reads on from it."""
asked = _site(monkeypatch, 5, 2)
monkeypatch.setattr(ats, "MAX_PAGES", 2)
target = "successfactors:careers.acme.com"
state: dict[str, str] = {}
def pull_once() -> list[Any]:
source = ats.ATSSource({"boards": [{"url": target, "label": "Acme", "params": {}}],
"run": "r"})
source.state = state
return list(source.fetch())
assert len(pull_once()) == 4
assert state[f"ats:complete:{target}"] == ""
assert json.loads(state[f"ats:sweep:{target}"])["cursor"] == [4, "1000000002"]
assert len(pull_once()) == 1
assert (state[f"ats:complete:{target}"], state[f"ats:swept:{target}"]) == ("1", "1")
assert json.loads(state[f"ats:ids:{target}"]) == [
f"{target}:{1_000_000_000 + n}" for n in range(5)]
assert [int(u.rsplit("=", 1)[1]) for u in asked] == [0, 2, 4]
def test_a_board_with_no_roles_is_complete_at_zero(monkeypatch: pytest.MonkeyPatch) -> None:
_site(monkeypatch, 0, 10)
assert ats._fetch_rows(object(), "successfactors:careers.acme.com") == ([], True) # type: ignore[arg-type]
def test_a_page_that_is_no_search_page_is_a_failure_not_an_empty_board(
monkeypatch: pytest.MonkeyPatch) -> None:
"""A challenge or an error page answered with 200 must not read as a
board whose roles are all gone."""
monkeypatch.setattr(ats, "_get", lambda *a, **kw: b"<html><body>Just a moment...</body></html>")
monkeypatch.setattr(ats, "PAGE_DELAY", 0)
with pytest.raises(ValueError, match="not a SuccessFactors search page"):
ats._fetch_rows(object(), "successfactors:careers.acme.com") # type: ignore[arg-type]
def test_a_prefix_is_in_the_search_url_and_scopes_the_read(
monkeypatch: pytest.MonkeyPatch) -> None:
asked = _site(monkeypatch, 12, 10, prefix="/MiR")
rows, complete = ats._fetch_rows(object(), "successfactors:jobs.teradyne.com/MiR") # type: ignore[arg-type]
assert asked[0] == "https://jobs.teradyne.com/MiR/search/?q=&locationsearch=&startrow=0"
assert len(rows) == 12 and complete
assert rows[0]["url"] == "https://jobs.teradyne.com/MiR/job/City-Role-1000000000/1000000000/"
def test_a_site_that_does_not_scope_is_read_whole_and_filtered(
monkeypatch: pytest.MonkeyPatch) -> None:
"""The page is the whole site's: complete against its total, and only the
roles under the prefix are rows."""
ids = list(range(1_000_000_000, 1_000_000_006))
mine = _table_page(ids[:3], 6, "/MiR")
other = _table_page(ids[3:], 6, "/Other").split("<tbody>")[1].split("</tbody>")[0]
page = mine.replace("</tbody>", other + "</tbody>")
monkeypatch.setattr(ats, "_get", lambda *a, **kw: page.encode())
monkeypatch.setattr(ats, "PAGE_DELAY", 0)
rows, complete = ats._fetch_rows(object(), "successfactors:jobs.acme.com/MiR") # type: ignore[arg-type]
assert [r["source_id"] for r in rows] == ["1000000000", "1000000001", "1000000002"]
assert complete
# ------------------------------------------------------------------- detail
def _detail(name: str, url: str = "https://careers.vestas.com/job/x/1431772533/") -> dict[str, Any]:
text = _read(name)
def get(asked: str, **_: Any) -> bytes:
assert asked == url
return text.encode()
return successfactors.detail(get, "careers.vestas.com", {"url": url}) # type: ignore[arg-type]
def test_detail_reads_the_description_the_date_and_the_places_of_an_address() -> None:
got = _detail("successfactors-job.html")
assert got["description"].startswith("## Senior Management | Full-Time | Commercial\nAre you")
assert "<" not in got["description"]
# `datePosted` is a Java date, "Tue Sep 29 02:00:00 UTC 2026".
assert got["posted"] == datetime(2026, 9, 29, 2, tzinfo=UTC)
# The locality and the country's name; the region is cut to "Seou" by the site.
assert got["location"] == "Seoul, South Korea"
assert got["places"] == [{"text": "Seoul, South Korea", "remote": None}]
assert "country" not in got # prep derives it from the places
def test_detail_keeps_every_address_of_a_role_at_several_places() -> None:
"""The page repeats the `jobLocation` block per place; the last one used to win."""
got = _detail("successfactors-places-detail.html")
assert [p["text"] for p in got["places"]] == [
"Seoul, South Korea", "Busan, South Korea", "Aarhus, Denmark"]
assert got["location"] == "Seoul, South Korea; Busan, South Korea; Aarhus, Denmark"
def test_the_listing_place_is_the_roles_only_place_until_its_page_is_read() -> None:
rows = successfactors.rows(_read("successfactors-table.html"), "careers.vestas.com")
assert rows[0]["places"] == [{"text": "Seoul, Seoul-teukpyolsi, South Korea", "remote": None}]
assert all(r["places"] == ([{"text": r["location"], "remote": None}] if r["location"] else [])
for r in rows)
def test_detail_reads_the_place_from_a_street_address() -> None:
"""Systematic and most other sites give one `streetAddress`, "City, CC, zip"."""
got = _detail("successfactors-job-street.html")
assert got["location"] == "Bern, Switzerland"
assert got["posted"] == datetime(2026, 9, 28, 2, tzinfo=UTC)
assert got["description"].startswith("## Senior Solution Engineer Defence")
def test_detail_of_a_page_without_microdata_gives_the_description_only() -> None:
"""Novo Nordisk: the listing's date and location stand."""
got = _detail("successfactors-job-plain.html")
assert set(got) == {"description"}
assert got["description"].startswith("## Process Supporter, Koriyama Factory\n")
assert "Your new role" in got["description"]
def test_detail_leaves_a_style_block_out_of_the_description() -> None:
page = ('<div itemtype="http://schema.org/JobPosting"><span itemprop="description">'
'<span class="jobdescription"><style>.a{color:red}</style><p>Build <b>things</b>.</p>'
'<span>Nested</span></span></span></div><p>Footer</p>')
got = successfactors.detail(lambda url, **kw: page.encode(), "careers.acme.com",
{"url": "https://careers.acme.com/job/x/1/"})
assert got == {"description": "Build things.\nNested"}
def test_detail_of_a_page_that_is_not_a_role_is_empty() -> None:
got = successfactors.detail(lambda url, **kw: b"<html>Search</html>", "careers.acme.com",
{"url": "https://careers.acme.com/job/x/1/"})
assert got == {}
def test_detail_is_read_through_the_shared_code_for_the_roles_not_read(
monkeypatch: pytest.MonkeyPatch) -> None:
"""`ats._read_details` binds `get` and takes only `DETAIL_FIELDS`."""
text = _read("successfactors-job.html")
monkeypatch.setattr(ats, "_get", lambda client, url, host, slug, **kw: text.encode())
monkeypatch.setattr(ats, "PAGE_DELAY", 0)
rows = successfactors.rows(_read("successfactors-table.html"), "careers.vestas.com")[:2]
out, done, failed = ats._read_details(object(), "successfactors:careers.vestas.com", # type: ignore[arg-type]
rows, True, set(), set())
assert done == {f"successfactors:careers.vestas.com:{r['source_id']}" for r in rows}
assert not failed
assert out[0]["location"] == "Seoul, South Korea"
assert out[0]["description"].startswith("## Senior Management")
assert out[0]["title"] == rows[0]["title"]
# ------------------------------------------------------------ slugs and hosts
GOOD = ["careers.vestas.com", "jobs.teradyne.com/MiR", "jobs.teradyne.com/Universal-Robots",
"jobb.dnb.no", "careers.acme.co.uk", "a-b.example.com/x_y/z1"]
HOSTILE = [
"careers.vestas.com@evil.example", "evil.example#careers.vestas.com",
"careers.vestas.com?x=1", "careers.vestas.com/..", "careers.vestas.com/../x",
"careers.vestas.com/%2f", "careers.vestas.com/a%2fb", "careers.vestas.com:8443",
"careers.vestas.com:443", "careers.vestas.com ", " careers.vestas.com", "careers vestas.com",
"careers.vestas.com\n", "careers.vestas.com/MiR\n", "careers.vestas.com/",
"careers.vestas.com//x", "careers.vestas.com/a b", "careers.vestas.com/a.b",
"careers.vestas.com\\x", "localhost", "localhost/MiR", "foo.localhost", "127.0.0.1",
"127.0.0.1/MiR", "2130706433", "1.2.3.4", "[::1]", "printer.local", "router.lan",
"metadata.google.internal", "nas.home.arpa", "foo.0x7f000001", "Careers.Vestas.com",
"vestas", "", ".", "..", "-a.example.com", "a-.example.com", "a..example.com",
"example.com.", ".example.com",
]
@pytest.mark.parametrize("slug", GOOD)
def test_a_dns_name_with_an_optional_prefix_is_a_slug(slug: str) -> None:
assert successfactors.slug_ok(slug)
assert ats.is_known_target(f"successfactors:{slug}")
@pytest.mark.parametrize("slug", HOSTILE)
def test_a_slug_that_could_reach_another_host_is_refused(slug: str) -> None:
assert not successfactors.slug_ok(slug), repr(slug)
assert not ats.is_known_target(f"successfactors:{slug}"), repr(slug)
def test_allowed_admits_the_sites_own_host_only() -> None:
allow = ats._allowed_host("successfactors", "jobs.teradyne.com/MiR")
assert allow("jobs.teradyne.com") and allow("JOBS.teradyne.com")
for other in ("teradyne.com", "www.teradyne.com", "career41.sapsf.com",
"career5.successfactors.eu", "jobs.teradyne.com.evil.example",
"evil.example", "127.0.0.1"):
assert not allow(other), other
def test_a_redirect_to_the_back_end_is_refused() -> None:
"""The back end's robots.txt disallows everything, so `get` never lands
there, whatever the career site redirects to."""
def handler(request: httpx.Request) -> httpx.Response:
return httpx.Response(302, headers={
"location": "https://career5.successfactors.eu/career?company=x"})
with httpx.Client(transport=httpx.MockTransport(handler)) as client, \
pytest.raises(ats._Refused):
ats._get(client, "https://careers.vestas.com/search/", "successfactors",
"careers.vestas.com")
def test_careers_url_is_the_search_page() -> None:
assert ats.careers_url("successfactors:careers.vestas.com") == \
"https://careers.vestas.com/search/"
assert ats.careers_url("successfactors:jobs.teradyne.com/MiR") == \
"https://jobs.teradyne.com/MiR/search/"
for slug in GOOD:
page = successfactors.careers_url(slug)
assert httpx.URL(page).host == slug.split("/")[0]
assert successfactors.allowed(slug)(httpx.URL(page).host)
def test_the_module_is_case_sensitive_about_the_prefix() -> None:
assert successfactors.KEEP_CASE is True
assert readers.HOSTS["successfactors"] is successfactors
assert successfactors._parts("jobs.teradyne.com/MiR") == ("jobs.teradyne.com", "/MiR")
# ---------------------------------------------------------------- discovery
def test_discovery_finds_a_board_from_a_link_to_one_of_its_roles() -> None:
page = ('<a href="https://careers.vestas.com/job/Seoul-Director%2C-Service-Commercial-Seou-04323'
'/1431772533/">Director</a>')
assert [(h, s) for h, s, _ in boards_in(page)] == [("successfactors", "careers.vestas.com")]
@pytest.mark.parametrize(("link", "slug"), [
# The `careers_url` of the seed's companies that name a search or a landing page.
("https://careers.vestas.com/search/?q=&locationsearch=", "careers.vestas.com"),
("https://jobs.systematic.com/search/?createNewAlert=false&amp;q=&amp;locationsearch=DE+%2B+AT",
"jobs.systematic.com"),
("https://jobs.scania.com/go/Jobs-at-Scania/9096601/", "jobs.scania.com"),
("https://careers.tryg.com/Tryg/go/All-open-positions/9394801/", "careers.tryg.com/Tryg"),
("https://careers.ovhcloud.com/search/?createNewAlert=false&q=&locationsearch=&locale=en_US",
"careers.ovhcloud.com"),
])
def test_discovery_finds_a_board_from_a_link_to_its_search_or_landing_page(
link: str, slug: str) -> None:
assert [(h, s) for h, s, _ in boards_in(f'<a href="{link}">Jobs</a>')] == [
("successfactors", slug)]
def test_discovery_takes_the_brand_segment_and_keeps_its_case() -> None:
page = '<a href="https://jobs.teradyne.com/MiR/job/Basak-PLM-Data-Analyst/1397096400/">x</a>'
assert [(h, s) for h, s, _ in boards_in(page)] == [("successfactors", "jobs.teradyne.com/MiR")]
def test_a_link_to_the_back_end_names_the_host_without_a_slug() -> None:
"""Bang & Olufsen's page: only the back end, which is not read, and a page
of a career site names it too. The host is named, no board."""
page = '<a href="https://career5.successfactors.eu/career?company=bangolufse">Jobs</a>'
assert [(h, s) for h, s, _ in boards_in(page)] == [("successfactors", "")]
page = '<img src="https://rmkcdn.successfactors.com/81de82ba/logo.png">'
assert [(h, s) for h, s, _ in boards_in(page)] == [("successfactors", "")]
@pytest.mark.parametrize("page", [
'<a href="https://careers.acme.com/job/Some-Role/12345/">short id</a>',
'<a href="https://boards.greenhouse.io/acme/jobs/4001234567">Greenhouse</a>',
'<a href="https://acme.wd3.myworkdayjobs.com/en-US/Site/job/City/Title_R123">Workday</a>',
'<a href="https://careers.acme.com/search/">only a search link</a>',
])
def test_a_link_that_is_no_successfactors_role_names_nothing(page: str) -> None:
assert not [found for found in boards_in(page) if found[0] == "successfactors"]