From 9d915ab09acc64ccd8313d372bc7b46bec0b1f62 Mon Sep 17 00:00:00 2001 From: Wolf Date: Tue, 29 Sep 2026 20:10:11 +0200 Subject: [PATCH] Test the SuccessFactors host against saved table, tile and job pages Co-Authored-By: Claude Sonnet 5.5 --- .../ats/successfactors-job-plain.html | 47 ++ .../ats/successfactors-job-street.html | 84 +++ tests/fixtures/ats/successfactors-job.html | 98 +++ tests/fixtures/ats/successfactors-prefix.html | 194 ++++++ tests/fixtures/ats/successfactors-robots.txt | 11 + tests/fixtures/ats/successfactors-shared.html | 253 ++++++++ .../ats/successfactors-table-nodate.html | 156 +++++ tests/fixtures/ats/successfactors-table.html | 243 ++++++++ .../ats/successfactors-tile-scania.html | 526 ++++++++++++++++ tests/fixtures/ats/successfactors-tile.html | 563 ++++++++++++++++++ tests/test_ats_successfactors.py | 493 +++++++++++++++ 11 files changed, 2668 insertions(+) create mode 100644 tests/fixtures/ats/successfactors-job-plain.html create mode 100644 tests/fixtures/ats/successfactors-job-street.html create mode 100644 tests/fixtures/ats/successfactors-job.html create mode 100644 tests/fixtures/ats/successfactors-prefix.html create mode 100644 tests/fixtures/ats/successfactors-robots.txt create mode 100644 tests/fixtures/ats/successfactors-shared.html create mode 100644 tests/fixtures/ats/successfactors-table-nodate.html create mode 100644 tests/fixtures/ats/successfactors-table.html create mode 100644 tests/fixtures/ats/successfactors-tile-scania.html create mode 100644 tests/fixtures/ats/successfactors-tile.html create mode 100644 tests/test_ats_successfactors.py diff --git a/tests/fixtures/ats/successfactors-job-plain.html b/tests/fixtures/ats/successfactors-job-plain.html new file mode 100644 index 0000000..005a1dd --- /dev/null +++ b/tests/fixtures/ats/successfactors-job-plain.html @@ -0,0 +1,47 @@ + +Process Supporter, Koriyama Factory 求人詳細 | Novo Nordisk + +
+
+
+

Process Supporter, Koriyama Factory

+ +
+

日付: 2026/09/29 +

+

+場所: +Koriyama, Fukushima, JP + +

+

+会社: +Novo Nordisk +

+
+

       

Process Supporter, Koriyama Factory

+

 

+

あなたの仕事が、世界中の患者さんの手に届く医薬品の品質と安定供給を支えます。生産ラインの担当として、製造現場の課題解決と継続的な改善を推進するポジションです。

+

 

+

Your new role

+

郡山工場の生産部門において、担当する製造ラインのプロセスサポーターとして、製造工程の安定稼働と品質向上に貢献していただきます。既存メンバーとラインごとに担当を分担し、生産部門全体の底上げを担う重要な役割です。

+

 

+

主な業務内容は以下の通りです:

+
    +
  • 担当製造(錠剤)ラインにおける製造プロセスの監視・分析・改善提案
  • +
  • 新規ライン立ち上げのためのサポート
  • +
  • 製造工程における逸脱やトラブルの原因調査および是正措置の実施
  • +
  • 標準作業手順書(SOP)の作成・更新および文書管理
  • +
  • 製造現場のオペレーターへの技術的サポートおよびトレーニング
  • +
  • 品質保証部門やエンジニアリング部門など、関連部署との連携・調整
  • +
  • 継続的改善(CI)活動の推進と生産効率の向上への貢献
  • +
+

 

+

Your new department

+

Global Manufacturing & Supplyでは、医薬品・デバイスの開発から製品化まで、バリューチェーン全体をカバーしています。世界中で30,000人以上の仲間が、分子・プロセス・デバイス・製品のスケールアップという共通の責任を担い、それを最も必要とする患者さんへ命を救う医薬品を届けることに尽力しています。

+

 

+

郡山工場のプロセスサポートチームは、生産部門全体の技術力向上を支える重要なチームです。前向きで協力的なメンバーが揃っており、チーム内の関係性が非常に良好で、互いに助け合う文化が根付いています。あなたもこのチームの一員として、製造現場の最前線で確かな貢献を実感できる環境で働くことができます。

+

 

+

Your skills & qualifications

diff --git a/tests/fixtures/ats/successfactors-job-street.html b/tests/fixtures/ats/successfactors-job-street.html new file mode 100644 index 0000000..54311cc --- /dev/null +++ b/tests/fixtures/ats/successfactors-job-street.html @@ -0,0 +1,84 @@ + +Senior Solution Engineer, Defence (m/w/d) - Bern, Schweiz Job Details | Systematic A/S + +
+
+
+
+Apply now » + +
+
+
+
+
+
+ +
+
+
+
+
+
+
+ +

Senior Solution Engineer Defence (m/w/d) – Bern, Schweiz

+


Möchtest Du taktische Kommunikationssysteme und C2-Lösungen für die Schweizer Armee mitgestalten und dabei deine technische Bandbreite voll ausschöpfen? Als Senior Solution Engineer bei Systematic bist Du zentraler Ansprechpartner für unsere Verteidigungskunden in Bern und Thun und begleitest Projekte von der Konzeption bis zum laufenden Betrieb.

+

 

+

Unser stark wachsendes Softwareunternehmen vereint über 1.100 engagierte Menschen an 15 attraktiven Standorten weltweit. Was uns besonders macht? Systematic hat dänische Wurzeln, agiert international und besitzt eine einzigartige Unternehmenskultur. Gemeinsam schreiben wir intelligenten und innovativen Code, denn unsere Kunden – vornehmlich Behörden und staatliche Einrichtungen im öffentlichen Sektor, dem Gesundheits- und Verteidigungswesen – vertrauen weltweit auf unsere innovativen Lösungen zur besseren Entscheidungsfindung in kritischen Situationen. Unsere DNA: #neverstopdeveloping

diff --git a/tests/fixtures/ats/successfactors-job.html b/tests/fixtures/ats/successfactors-job.html new file mode 100644 index 0000000..ea88097 --- /dev/null +++ b/tests/fixtures/ats/successfactors-job.html @@ -0,0 +1,98 @@ + +Director, Service Commercial Job Details | Vestas + +
+
+
+
+ +
+
+
+
+
+
+

+Director, Service Commercial + +

+
+
+
+
+
+
+
+
+Requisition ID:  + +78026 + +
+
+
+
+
+
+
+
+Location(s):  + + +

+Seoul, Seoul-teukpyolsi, KR, 04323 + +

+
+
+
+
+
+
+
+
+
+Work experience:  + +Senior Management + +
+
+
+
+
+
+
+
+Type of position:  + +Full-Time + +
+
+
+
+
+
+
+
+Job Family:  + +Commercial + +
+
+
+
+
+
+
+
+ +

 Vestas Factory

+

Senior Management | Full-Time | Commercial 

Are you an inspiring, customer-centric people leader with a clear commercial focus? Then this could be an opportunity for you.

+

The Service Commercial Asia team is a motivated, international group that thrives at the intersection of customer value and commercial performance. With diverse perspectives spanning regions and cultures, we support our offshore and onshore service business in Asia. We are commercially minded and deeply customer focused, looking beyond the numbers to understand our customers’ real challenges and opportunities. Curiosity and innovation guide how we work, how we partner with customers, and how we grow the business. Collaboration, openness, and progressive thinking define our culture - creating a team where ideas are welcomed, people are supported in their development, and impact is visible on a global scale.

+

 

+

Responsibilities

diff --git a/tests/fixtures/ats/successfactors-prefix.html b/tests/fixtures/ats/successfactors-prefix.html new file mode 100644 index 0000000..b2d4114 --- /dev/null +++ b/tests/fixtures/ats/successfactors-prefix.html @@ -0,0 +1,194 @@ + +Teradyne Jobs + +iv> + +
+
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +Title + + + + +Location + + + + +Function + + + + +Subsidiary + + +
+ + + + + + + + +
+ + + + +Reset +
+
+ +Senior Software Engineer (Universal Robots, Bangalore - India) + + + + +Bangalore, IN + + +Information Technology + +Universal-Robots +
+ +Robotics Software Test Engineer (Universal Robots, Bangalore - India) + + + + +Bangalore, IN + + +Information Technology + +Universal-Robots +
+ +Customer Service Engineer + +
+ +Customer Service Engineer + + + +Seongnam-si, KR + +
+
+ +Seongnam-si, KR + + +Engineering + +Universal-Robots +
+ +Salesforce Developer (Universal Robots, Bangalore - India) + + + + +Bangalore, IN + + +Information Technology + +Universal-Robots +
diff --git a/tests/fixtures/ats/successfactors-robots.txt b/tests/fixtures/ats/successfactors-robots.txt new file mode 100644 index 0000000..02e3127 --- /dev/null +++ b/tests/fixtures/ats/successfactors-robots.txt @@ -0,0 +1,11 @@ +User-agent: * +Disallow: /applybutton/ +Disallow: /talentcommunity/ +Disallow: /mobile/talentcommunity/ +Disallow: /emailsubscribe/ +Disallow: /email/image/ +Disallow: /services/ +Disallow: /preapply/ +Disallow: /error +Disallow: /unsubscribe/ +Disallow: /reset/ \ No newline at end of file diff --git a/tests/fixtures/ats/successfactors-shared.html b/tests/fixtures/ats/successfactors-shared.html new file mode 100644 index 0000000..61f0d7f --- /dev/null +++ b/tests/fixtures/ats/successfactors-shared.html @@ -0,0 +1,253 @@ + +Teradyne Jobs + +iv> + +
+
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +Title + + + + +Location + + + + +Function + + + + +Subsidiary + + +
+ + + + + + + + +
+ + + + +Reset +
+
+ +PLM Data Analyst (MiR R&D, Philippines: Cebu) + +
+ +PLM Data Analyst (MiR R&D, Philippines: Cebu) + + + +Basak, Lapu-Lapu City, PH + +
+
+ +Basak, Lapu-Lapu City, PH + + +Engineering + +MiR +
+ +Senior Mechanical Engineer (Teradyne, North Reading, MA) + + + + +North Reading, MA, US + + +Engineering + +Teradyne +
+ +Customer Production Support Engineer + +
+ +Customer Production Support Engineer + + + +Jubei City, TW + +
+
+ +Jubei City, TW + + +Engineering + +Teradyne +
+ +Head of Corporate Communications (Teradyne, North Reading, MA) + + + + +North Reading, MA, US + + +Marketing + +Teradyne +
+ +Memory Test Product Management Manager (Memory Test, San Jose, CA) + + + + +San Jose, CA, US + + +Marketing + +Teradyne +
+ +Field Application Engineer + +
+ +Field Application Engineer + + + +Jubei City, TW + +
+
+ +Jubei City, TW + + +Engineering + +Teradyne +
diff --git a/tests/fixtures/ats/successfactors-table-nodate.html b/tests/fixtures/ats/successfactors-table-nodate.html new file mode 100644 index 0000000..920b446 --- /dev/null +++ b/tests/fixtures/ats/successfactors-table-nodate.html @@ -0,0 +1,156 @@ + +SAP Jobs + +iv> + +
+
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +Title + + + + +City + + +
+ + + + +
+ + + + + +Reset +
+
+ +Technical Services Manager (TSM) - with SAP BASIS + +
+ +Technical Services Manager (TSM) - with SAP BASIS + + + +Budapest, HU, 1031 + +
+
+ +Budapest, HU, 1031 + +
+ +HR Total Rewards Consultant (fixed-term) + +
+ +HR Total Rewards Consultant (fixed-term) + + + +'s-Hertogenbosch, NL, 5232 BE + +
+
+ +'s-Hertogenbosch, NL, 5232 BE + +
+ +Working Student / Intern (f/m/d) - Go-to-Market Strategy & Operations | Germany 2026 + + + + +Walldorf, DE, 69190 + +
+ +SAP China iXp Intern - Intern Queue Manager for Technial Support - Dalian + + + + +Dalian China, CN, 116023 + +
diff --git a/tests/fixtures/ats/successfactors-table.html b/tests/fixtures/ats/successfactors-table.html new file mode 100644 index 0000000..4496600 --- /dev/null +++ b/tests/fixtures/ats/successfactors-table.html @@ -0,0 +1,243 @@ + +Vestas Jobs + +
+
+
+
+
+ +
+
+
+
+
+
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +Job Title + + + + +Location + + + + +Job Family + + + + +Work Experience + + +
+ + + + + + + + +
+ + + + +Reset +
+
+ +Director, Service Commercial + +
+ +Director, Service Commercial + + + +Seoul, Seoul-teukpyolsi, KR, 04323 + +29 Sept 2026 + +
+
+ +Seoul, Seoul-teukpyolsi, KR, 04323 + + +Commercial + +Senior Management +
+ +Stock Keeper + +
+ +Stock Keeper + + + +Chetwynd, British Columbia, CA + +29 Sept 2026 + +
+
+ +Chetwynd, British Columbia, CA + + +Supply Chain and Logistics + +Skilled Worker / Semi-Skilled Worker +
+ +Wind Technician II Panther Grove II- Gridley, IL + +
+ +Wind Technician II Panther Grove II- Gridley, IL + + + +Gridley, IL, US + +29 Sept 2026 + +
+
+ +Gridley, IL, US + + +Field Operations + +Skilled Worker / Semi-Skilled Worker +
+ +Wind Site Technician III - Moriarty, NM + +
+ +Wind Site Technician III - Moriarty, NM + + + +Clines Corners, NM, US + +29 Sept 2026 + +
+
+ +Clines Corners, NM, US + + +Field Operations + +Skilled Worker / Semi-Skilled Worker +
+ +Manufacturing Finance Controller + +
+ +Manufacturing Finance Controller + + + +Pasay, 00, PH, 1300 + +29 Sept 2026 + +
+
+ +Pasay, 00, PH, 1300 + + +Finance + +Professional +
diff --git a/tests/fixtures/ats/successfactors-tile-scania.html b/tests/fixtures/ats/successfactors-tile-scania.html new file mode 100644 index 0000000..0c4ed97 --- /dev/null +++ b/tests/fixtures/ats/successfactors-tile-scania.html @@ -0,0 +1,526 @@ + +Scania Jobs + +-button btn-link">Clear filters +
+ + + + + + +
+
+
+ +
+Showing 1 to 15 of 763 Jobs + +
    +
  • +
    +
    + + + +Select with space bar to view the full contents of the job information. +
    +
    +
  • +
  • +
    +
    + + + +Select with space bar to view the full contents of the job information. +
    +
    +
  • +
  • +
    +
    + + + +Select with space bar to view the full contents of the job information. +
    +
    +
  • +
diff --git a/tests/fixtures/ats/successfactors-tile.html b/tests/fixtures/ats/successfactors-tile.html new file mode 100644 index 0000000..2f4fe17 --- /dev/null +++ b/tests/fixtures/ats/successfactors-tile.html @@ -0,0 +1,563 @@ + +Jobs + +ss="search-clear-button btn-link">Clear + + + + + + + +
+
+
+ +
+Showing 1 to 10 of 307 Jobs + +
diff --git a/tests/test_ats_successfactors.py b/tests/test_ats_successfactors.py new file mode 100644 index 0000000..6a1eb71 --- /dev/null +++ b/tests/test_ats_successfactors.py @@ -0,0 +1,493 @@ +"""The SuccessFactors host: `plugins/atshosts/successfactors.py` against saved +career-site pages. 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 sys +from datetime import UTC, datetime +from pathlib import Path +from typing import Any + +import httpx +import pytest + +ROOT = Path(__file__).resolve().parents[1] +if str(ROOT) not in sys.path: + sys.path.insert(0, str(ROOT)) + +from app.jobs.discover import boards_in # noqa: E402 +from plugins import ats, atshosts # noqa: E402 +from plugins.atshosts import successfactors # noqa: E402 + +FIXTURES = ROOT / "tests" / "fixtures" / "ats" + + +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'' + f'Role {i}' + f'City, DK, 2100' + f'29 Sept 2026' for i in ids) + return (f'Results 1 to {len(ids)} of {total}' + f'{body}
') + + +def _tile_page(ids: list[int], total: int, prefix: str = "") -> str: + body = "".join( + f'
  • ' + f'Role {i}' + f'Date' + f'
    Sep 29, 2026
    ' + f'Location' + f'
    City, DK, 2100
  • ' for i in ids) + return (f'Showing 1 to {len(ids)} of {total} Jobs' + f'') + + +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 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"Just a moment...") + 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("")[1].split("")[0] + page = mine.replace("", other + "") + 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_country_code_of_an_address() -> None: + got = _detail("successfactors-job.html") + assert got["description"].startswith("Senior Management | Full-Time | Commercial Are 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 set(got) <= set(ats.DETAIL_FIELDS) + + +def test_detail_reads_the_country_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") + assert "Your new role" in got["description"] + + +def test_detail_leaves_a_style_block_out_of_the_description() -> None: + page = ('
    ' + '

    Build things.

    ' + 'Nested

    Footer

    ') + got = successfactors.detail(lambda url, **kw: page.encode(), "careers.acme.com", + {"url": "https://careers.acme.com/job/x/1/"}) + assert got == {"description": "Build things. Nested"} + + +def test_detail_of_a_page_that_is_not_a_role_is_empty() -> None: + got = successfactors.detail(lambda url, **kw: b"Search", "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_and_robots_page_are_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.robots_page(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 atshosts.HOSTS["successfactors"] is successfactors + assert successfactors._parts("jobs.teradyne.com/MiR") == ("jobs.teradyne.com", "/MiR") + + +# ------------------------------------------------------------------ robots + +def test_the_robots_txt_of_these_sites_allows_search_and_jobs_not_services() -> None: + robots = (FIXTURES / "successfactors-robots.txt").read_bytes() + for slug in GOOD: + assert ats._robots_allows(robots, successfactors.robots_page(slug)), slug + assert ats._robots_allows(robots, "https://careers.vestas.com/job/x/1431772533/") + assert not ats._robots_allows(robots, "https://careers.vestas.com/services/rss/job/") + assert not ats._robots_allows(robots, "https://careers.vestas.com/talentcommunity/apply/1/") + + +def test_a_site_that_disallows_its_search_is_refused(monkeypatch: pytest.MonkeyPatch) -> None: + robots = b"User-agent: *\nDisallow: /search/\n" + monkeypatch.setattr(ats, "_get", lambda client, url, host, slug, **kw: robots) + with pytest.raises(ats._Disallowed): + ats._check_robots(object(), "successfactors:careers.acme.com") # type: ignore[arg-type] + + +# ---------------------------------------------------------------- discovery + +def test_discovery_finds_a_board_from_a_link_to_one_of_its_roles() -> None: + page = ('Director') + assert [(h, s) for h, s, _ in boards_in(page)] == [("successfactors", "careers.vestas.com")] + + +def test_discovery_takes_the_brand_segment_and_keeps_its_case() -> None: + page = 'x' + 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 = 'Jobs' + assert [(h, s) for h, s, _ in boards_in(page)] == [("successfactors", "")] + page = '' + assert [(h, s) for h, s, _ in boards_in(page)] == [("successfactors", "")] + + +@pytest.mark.parametrize("page", [ + 'short id', + 'Greenhouse', + 'Workday', + 'only a search link', +]) +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"]