From d80754e9856d9dfbce04d3edf01a6670ef7b395f Mon Sep 17 00:00:00 2001 From: Wolf Date: Tue, 29 Sep 2026 20:13:23 +0200 Subject: [PATCH] Read HR Manager's public position feed by skip and take Co-Authored-By: Claude Sonnet 5.5 --- plugins/atshosts/hrmanager.py | 114 ++++++++++++++ tests/fixtures/ats/hrmanager-empty.xml | 1 + tests/fixtures/ats/hrmanager.xml | 91 ++++++++++++ tests/test_ats_hrmanager.py | 196 +++++++++++++++++++++++++ 4 files changed, 402 insertions(+) create mode 100644 plugins/atshosts/hrmanager.py create mode 100644 tests/fixtures/ats/hrmanager-empty.xml create mode 100644 tests/fixtures/ats/hrmanager.xml create mode 100644 tests/test_ats_hrmanager.py diff --git a/plugins/atshosts/hrmanager.py b/plugins/atshosts/hrmanager.py new file mode 100644 index 0000000..6bde149 --- /dev/null +++ b/plugins/atshosts/hrmanager.py @@ -0,0 +1,114 @@ +"""HR Manager (Talentech): `hrmanager:`, the public RSS of a +company's job portal, paged by `skip` and `take` with no stated total. + +Written from four real boards on 2026-09-29: STS Group (6 roles), Flying +Tiger and KPMG (25 or more), and NNIT (none). The feed is +`api.hr-manager.net/JobPortal.svc//PositionList/rss/?incads=true`; +without `take` it answers the first 25 roles whatever the board holds, and +`skip` and `take` were seen to page it (25 more with `skip=25`, 100 with +`take=100`). The customer is not case-sensitive (`FLYINGTIGER` answers as +`flyingtiger` does). + +robots.txt: the portal's own pages on candidate.hr-manager.net disallow +everything for `*` except the application form, and so `robots_page` is the +feed's URL, on the API host, which has no robots.txt (a 404, which allows). +The feed is the interface HR Manager publishes for readers like this one; the +portal's HTML list, which the robots.txt does shut out, is never read. The +role's link is the application form the robots.txt names as allowed, and is +only shown, not fetched. +""" + +from __future__ import annotations + +import html +import re +import xml.etree.ElementTree as ET +from collections.abc import Callable +from typing import Any + +from desk.sources import strip_html + +from ._shared import Get, Page, Row, is_web_url, only, parse_dt + +NAME = "hrmanager" +LABEL = "HR Manager" +PATTERNS = ( + r"hr-manager\.net/vacancies/list\.aspx\?(?:[^\"'\s#<>]*?[&;])?customer=([A-Za-z0-9][A-Za-z0-9_-]*)", + r"api\.hr-manager\.net/JobPortal\.svc/([A-Za-z0-9][A-Za-z0-9_-]*)/", +) + +_API = "api.hr-manager.net" + +#: The roles asked for in one page. 100 were served at once at Flying Tiger; the +#: cursor moves on by what a page returned, so a smaller cap on the host's +#: side would not skip a role, and the read ends on an empty page. +PAGE_SIZE = 100 + +_SLUG = re.compile(r"[A-Za-z0-9][A-Za-z0-9_-]*") + + +def slug_ok(slug: str) -> bool: + return bool(_SLUG.fullmatch(slug)) + + +def allowed(slug: str) -> Callable[[str], bool]: + return only(_API) + + +def careers_url(slug: str) -> str: + return f"https://candidate.hr-manager.net/vacancies/list.aspx?customer={slug}" + + +def _feed(slug: str, skip: int) -> str: + return (f"https://{_API}/JobPortal.svc/{slug}/PositionList/rss/" + f"?incads=true&skip={skip}&take={PAGE_SIZE}") + + +def robots_page(slug: str) -> str: + return _feed(slug, 0) + + +def page(get: Get, slug: str, cursor: Any) -> Page: + skip = int(cursor or 0) + items = _items(get(_feed(slug, skip), headers={"Accept": "application/rss+xml"})) + results = [{"id": item.findtext("guid") or item.findtext("link") or ""} for item in items] + return items, results, None, skip + len(items) if items else None + + +def parse(body: bytes, slug: str) -> list[Row]: + return rows(_items(body), slug) + + +def _items(body: bytes) -> list[ET.Element]: + """`...`. A board with no open roles is a channel + with no items, which is an empty board; an answer without a channel is + not a feed, and raises.""" + channel = ET.fromstring(body).find("channel") + if channel is None: + raise ValueError("not an HR Manager feed: no channel") + return channel.findall("item") + + +def rows(items: list[ET.Element], slug: str) -> list[Row]: + """One page of items. An item has the `guid` (the position's id), `link` + (its application form), `title`, the whole advertisement as escaped HTML + in `description` and `pubDate`. It names no place, department or pay: the + place, where there is one, is in the title or the text.""" + out = [] + 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 + out.append({ + "source_id": (item.findtext("guid") or url).strip(), + "title": title, + "location": "", + "url": url, + "posted": parse_dt(item.findtext("pubDate")), + "department": "", + "description": html.unescape(strip_html(item.findtext("description") or "")), + "remote": None, + "salary_text": "", + }) + return out diff --git a/tests/fixtures/ats/hrmanager-empty.xml b/tests/fixtures/ats/hrmanager-empty.xml new file mode 100644 index 0000000..aa322d3 --- /dev/null +++ b/tests/fixtures/ats/hrmanager-empty.xml @@ -0,0 +1 @@ +HR Manager Talent Recruiter - Position Listhttps://candidate.hr-manager.net/vacancies/list.aspx?customer=nnitHR Manager Talent Recruiter - Position ListTue, 29 Sep 2026 20:10:59 +0200 \ No newline at end of file diff --git a/tests/fixtures/ats/hrmanager.xml b/tests/fixtures/ats/hrmanager.xml new file mode 100644 index 0000000..08883bb --- /dev/null +++ b/tests/fixtures/ats/hrmanager.xml @@ -0,0 +1,91 @@ +HR Manager Talent Recruiter - Position Listhttps://candidate.hr-manager.net/vacancies/list.aspx?customer=stsgroup_trHR Manager Talent Recruiter - Position ListTue, 29 Sep 2026 20:11:15 +0200143857https://candidate.hr-manager.net/ApplicationInit.aspx?cid=2523&ProjectId=143857&DepartmentId=18958&MediaId=5Commissioning Engineer- T&D<p><strong>About the Position</strong></p> + +<p style="text-align:justify">We have an exciting opportunity for a Commissioning Engineer, to join STS Group T&D Division.</p> + +<p style="text-align:justify">The position will be located in Ireland.</p> + +<p style="text-align:justify"><br /> +STS Group, is dedicated to being the leading and most cost-efficient provider of electrical engineering, instrumentation, design and commissioning services across Ireland, UK, Europe and the Middle East. Since its formation, STS Group has broadened its scope to become a full-service provider to world renowned brand names in the Pharmaceutical, Data Centre, Utilities, Oil, Gas & Chemicals, Food & Beverage, Transport and other industry sectors.</p> + +<p style="text-align:justify">Headquartered in Waterford, Ireland, STS Group is one of three business units within Dussmann Technical Solutions (DTS) and is a proud member of the Dussmann Group. STS Group employs the best people, invests heavily in training and education ensuring that the highest standards of health, safety and governance are applied throughout the organisation</p> + +<p><br /> +<strong>What you will be doing?</strong></p> + +<ul> + <li>Tue, 18 Mar 2025 17:31:36 +01002025-04-02T12:30:03+02:00143844https://candidate.hr-manager.net/ApplicationInit.aspx?cid=2523&ProjectId=143844&DepartmentId=18958&MediaId=5Electrical Tester- Dublin<p>The Company</p> + +<p>STS Group, is dedicated to being the leading and most cost-efficient provider of electrical engineering, instrumentation, design and commissioning services across Ireland, UK, Europe and the Middle East. Since its formation, STS Group has broadened its scope to become a full-service provider to world renowned brand names in the Pharmaceutical, Data Centre, Utilities, Oil, Gas & Chemicals, Food & Beverage, Transport and other industry sectors.</p> + +<p>Headquartered in Waterford, Ireland, STS Group is one of three business units within Dussmann Technical Solutions (DTS) and is a proud member of the Dussmann Group. STS Group employs the best people, invests heavily in training and education ensuring that the highest standards of health, safety and governance are applied throughout the organisation.</p> + +<p> </p> + +<p> </p> + +<p>*This company is an equal opportunities employer*</p> + +<p> </p> + +<p>Job description</p> + +<p> </p> + +<p> </p> + +<p>Duties & Responsibilities:</p> + +<ul> + <li>Fully qualified Electrician with current <strong>Safe Electric (RECI) Certification</strong>.</li>Tue, 18 Feb 2025 11:02:55 +01002025-02-18T11:05:30+01:00143854https://candidate.hr-manager.net/ApplicationInit.aspx?cid=2523&ProjectId=143854&DepartmentId=18958&MediaId=5Pre Apprentice- Dublin 15<p>Are you a pre Apprentice? Join Our Apprenticeship Program – Your Future Starts Here!</p> + +<p>Are you ready to jumpstart your career in Electrical & Instrumentation? We're on the lookout for passionate pre-apprentices to join our team. Here’s why this opportunity is a game-changer:</p> + +<p>What’s in It for You?</p> + +<p>· Get Rewarded: Signing bonus plus a €1,000 Exceptional Performance Award for every successful apprenticeship year.</p> + +<p>· Real-World Training: Learn by doing, with hands-on experience from day one.</p> + +<p>· Globally Recognised Certification: Open doors anywhere in the world with industry-approved qualifications.</p> + +<p>· Secure Your Future: Enjoy job stability and countless opportunities for growth.</p> + +<p>· Climb the Ladder: Our "Beyond Apprentice" program fast-tracks your career progression.</p> + +<p>· Work Variety: Gain experience in diverse environments and departments.</p> + +<p>· Stay Ahead: Master cutting-edge technologies and stay at the forefront of innovation.</p> + +<p>What You’ll Be Doing</p> + +<p>Tue, 11 Mar 2025 16:30:53 +01002025-03-11T16:32:11+01:00143849https://candidate.hr-manager.net/ApplicationInit.aspx?cid=2523&ProjectId=143849&DepartmentId=18958&MediaId=5QS- Cork<p><strong>The Company</strong></p> + +<p>STS Group, is dedicated to being the leading and most cost-efficient provider of electrical engineering, instrumentation, design and commissioning services across Ireland, UK, Europe and the Middle East. Since its formation, STS Group has broadened its scope to become a full-service provider to world renowned brand names in the Pharmaceutical, Data Centre, Utilities, Oil, Gas & Chemicals, Food & Beverage, Transport and other industry sectors.</p> + +<p>Headquartered in Waterford, Ireland, STS Group is one of three business units within Dussmann Technical Solutions (DTS) and is a proud member of the Dussmann Group. STS Group employs the best people, invests heavily in training and education ensuring that the highest standards of health, safety and governance are applied throughout the organisation</p> + +<p>*This company is an equal opportunities employer*</p> + +<p> </p> + +<p><strong>Quantity Surveyor Criteria:</strong></p> + +<ul> + <li>2+ years Post-Graduate experience with a Main Contractor/ Developer.</li> + <li>Qualification in Quantity Surveying or similar area</li> + <li>Thu, 06 Mar 2025 15:30:00 +01002025-03-06T15:33:46+01:00143848https://candidate.hr-manager.net/ApplicationInit.aspx?cid=2523&ProjectId=143848&DepartmentId=18958&MediaId=5QS- Dublin<p><strong>The Company</strong></p> + +<p>STS Group, is dedicated to being the leading and most cost-efficient provider of electrical engineering, instrumentation, design and commissioning services across Ireland, UK, Europe and the Middle East. Since its formation, STS Group has broadened its scope to become a full-service provider to world renowned brand names in the Pharmaceutical, Data Centre, Utilities, Oil, Gas & Chemicals, Food & Beverage, Transport and other industry sectors.</p> + +<p>Headquartered in Waterford, Ireland, STS Group is one of three business units within Dussmann Technical Solutions (DTS) and is a proud member of the Dussmann Group. STS Group employs the best people, invests heavily in training and education ensuring that the highest standards of health, safety and governance are applied throughout the organisation</p> + +<p>*This company is an equal opportunities employer*</p> + +<p> </p> + +<p><strong>Senior Quantity Surveyor Criteria:</strong></p> + +<ul> + <li>2 + years Post-Graduate experience with a Main Contractor/ Developer.</li> + <li>Qualification in Quantity Surveying or similar area</li> + <li>Thu, 06 Mar 2025 15:11:42 +01002025-03-06T15:29:29+01:00 \ No newline at end of file diff --git a/tests/test_ats_hrmanager.py b/tests/test_ats_hrmanager.py new file mode 100644 index 0000000..c1015f0 --- /dev/null +++ b/tests/test_ats_hrmanager.py @@ -0,0 +1,196 @@ +"""The HR Manager host module against saved feeds (STS Group's, trimmed to +five roles, and NNIT's, which had none), 2026-09-29. No network.""" + +from __future__ import annotations + +import sys +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 hrmanager # noqa: E402 + +FIXTURES = ROOT / "tests" / "fixtures" / "ats" +BOARD = (FIXTURES / "hrmanager.xml").read_bytes() +EMPTY = (FIXTURES / "hrmanager-empty.xml").read_bytes() +FEED = "https://api.hr-manager.net/JobPortal.svc/stsgroup_tr/PositionList/rss/?incads=true" + + +def _feed(skip: int, slug: str = "stsgroup_tr") -> str: + return (f"https://api.hr-manager.net/JobPortal.svc/{slug}/PositionList/rss/" + f"?incads=true&skip={skip}&take=100") + + +def test_rows_read_the_advertisement_and_the_publication_date() -> None: + rows = hrmanager.parse(BOARD, "stsgroup_tr") + assert [r["source_id"] for r in rows] == ["143857", "143844", "143854", "143849", "143848"] + first = rows[0] + assert first["title"] == "Commissioning Engineer- T&D" # `&` in the XML + assert first["url"] == ("https://candidate.hr-manager.net/ApplicationInit.aspx" + "?cid=2523&ProjectId=143857&DepartmentId=18958&MediaId=5") + assert first["description"].startswith("About the Position We have an exciting opportunity") + assert "<" not in first["description"] and "&" not in first["description"] + assert "T&D Division" in first["description"] + assert first["posted"] is not None and first["posted"].isoformat() == \ + "2025-03-18T17:31:36+01:00" + # The feed names no place, department, pay or way of working. + assert (first["location"], first["department"], first["salary_text"], first["remote"]) == \ + ("", "", "", None) + + +def test_a_channel_with_no_items_is_an_empty_board_and_another_answer_is_not_a_feed() -> None: + assert hrmanager.parse(EMPTY, "nnit") == [] + with pytest.raises(ValueError, match="not an HR Manager feed"): + hrmanager.parse(b"404 - File or directory not found.", "x") + + +def test_an_item_without_a_title_or_a_web_link_is_skipped() -> None: + body = (b"1 https://a.example/1" + b"2Bjavascript:alert(1)" + b"3Chttps://a.example/3" + b"") + assert [r["source_id"] for r in hrmanager.parse(body, "x")] == ["3"] + + +# ------------------------------------------------------------- paging + +def _paged(answers: dict[str, bytes], asked: list[str]) -> Any: + def get(url: str, *, method: str = "GET", payload: Any = None, + headers: dict[str, str] | None = None) -> bytes: + asked.append(url) + return answers[url] + return get + + +def test_the_page_moves_on_by_what_it_returned_and_ends_on_an_empty_one() -> None: + asked: list[str] = [] + get = _paged({_feed(0): BOARD, _feed(5): EMPTY}, asked) + data, results, total, cursor = hrmanager.page(get, "stsgroup_tr", None) + assert len(results) == 5 and total is None and cursor == 5 + assert len(hrmanager.rows(data, "stsgroup_tr")) == 5 + _, results, total, cursor = hrmanager.page(get, "stsgroup_tr", cursor) + assert results == [] and total is None and cursor is None + assert asked == [_feed(0), _feed(5)] + + +@pytest.fixture +def web(monkeypatch: pytest.MonkeyPatch) -> dict[str, Any]: + answers: dict[str, Any] = {} + asked: list[str] = [] + + def fake_get(client, url, host, slug, *, method="GET", payload=None, headers=None, + www_twin=False): + asked.append(url) + if not ats._allowed_host(host, slug)(httpx.URL(url).host): + raise ats._Refused(url) + answer = answers[url] + if isinstance(answer, BaseException): + raise answer + return answer + + monkeypatch.setattr(ats, "_get", fake_get) + monkeypatch.setattr(ats, "PAGE_DELAY", 0) + return {"answers": answers, "asked": asked} + + +def test_a_board_is_complete_when_the_read_ends_on_an_empty_page(web: dict[str, Any]) -> None: + web["answers"] |= {_feed(0): BOARD, _feed(5): EMPTY} + with httpx.Client() as client: + rows, complete = ats._fetch_rows(client, "hrmanager:stsgroup_tr") + assert len(rows) == 5 and complete + assert web["asked"] == [_feed(0), _feed(5)] + + +def test_a_board_with_no_roles_is_complete_and_empty(web: dict[str, Any]) -> None: + web["answers"][_feed(0, "seaborg_tr")] = EMPTY + with httpx.Client() as client: + assert ats._fetch_rows(client, "hrmanager:seaborg_tr") == ([], True) + assert web["asked"] == [_feed(0, "seaborg_tr")] + + +def test_a_page_the_host_repeats_leaves_the_board_incomplete(web: dict[str, Any]) -> None: + """A host that ignored `skip` would answer the same roles again.""" + web["answers"] |= {_feed(0): BOARD, _feed(5): BOARD} + with httpx.Client() as client: + rows, complete = ats._fetch_rows(client, "hrmanager:stsgroup_tr") + assert len(rows) == 5 and not complete + + +def test_a_429_after_the_first_page_ends_the_read_incomplete(web: dict[str, Any]) -> None: + request = httpx.Request("GET", _feed(5)) + web["answers"] |= {_feed(0): BOARD, _feed(5): httpx.HTTPStatusError( + "429", request=request, response=httpx.Response(429, request=request))} + with httpx.Client() as client: + rows, complete = ats._fetch_rows(client, "hrmanager:stsgroup_tr") + assert len(rows) == 5 and not complete + + +def test_robots_are_read_from_the_api_host_whose_404_allows(web: dict[str, Any]) -> None: + request = httpx.Request("GET", "https://api.hr-manager.net/robots.txt") + web["answers"]["https://api.hr-manager.net/robots.txt"] = httpx.HTTPStatusError( + "404", request=request, response=httpx.Response(404, request=request)) + state: dict[str, str] = {} + with httpx.Client() as client: + ats._check_robots(client, "hrmanager:stsgroup_tr", state) + assert '"allowed": true' in state["ats:robots:hrmanager:stsgroup_tr"] + assert web["asked"] == ["https://api.hr-manager.net/robots.txt"] + + +def test_the_robots_page_is_the_feed_so_that_its_own_hosts_rules_decide( + web: dict[str, Any]) -> None: + web["answers"]["https://api.hr-manager.net/robots.txt"] = \ + b"User-agent: *\nDisallow: /JobPortal.svc/\n" + with httpx.Client() as client, pytest.raises(ats._Disallowed): + ats._check_robots(client, "hrmanager:stsgroup_tr") + + +# ------------------------------------------------------- slugs and hosts + +def test_the_module_is_registered_as_a_paged_host() -> None: + assert atshosts.HOSTS["hrmanager"] is hrmanager and ats.HOSTS["hrmanager"] == "HR Manager" + assert hrmanager.NAME == "hrmanager" and not getattr(hrmanager, "KEEP_CASE", False) + assert hasattr(hrmanager, "page") and not hasattr(hrmanager, "detail") + + +def test_the_urls_and_the_allowed_host() -> None: + assert hrmanager.careers_url("seaborg_tr") == \ + "https://candidate.hr-manager.net/vacancies/list.aspx?customer=seaborg_tr" + assert hrmanager.robots_page("stsgroup_tr") == _feed(0) + allow = hrmanager.allowed("stsgroup_tr") + assert allow("api.hr-manager.net") and allow("API.HR-MANAGER.NET") + for host in ("candidate.hr-manager.net", "hr-manager.net", "api.hr-manager.net.evil.example", + "localhost"): + assert not allow(host) + + +@pytest.mark.parametrize("slug", ["seaborg_tr", "kpmg", "FlyingTiger", "a-b", "9x"]) +def test_a_customer_is_one_path_segment(slug: str) -> None: + assert ats.is_known_target(f"hrmanager:{slug}") + + +@pytest.mark.parametrize("slug", [ + "", "a@b", "a#b", "a?b", "a&skip=1", "..", ".", "a%2fb", "%2f", "a/b", "a:443", "a b", + "acme\n", " acme", "acme ", "127.0.0.1", "a.b", "_x", "-x", "a\\b", "évil", +]) +def test_a_hostile_slug_is_refused(slug: str) -> None: + assert not hrmanager.slug_ok(slug) + assert not ats.is_known_target(f"hrmanager:{slug}") + + +def test_discovery_finds_the_customer() -> None: + page = ('Jobs' + 'KPMG' + 'N' + 'R' + 'A') + assert [(h, s) for h, s, _ in boards_in(page)] == [ + ("hrmanager", "seaborg_tr"), ("hrmanager", "kpmg"), ("hrmanager", "nnit"), + ("hrmanager", "flyingtiger")]