Read Deel's job boards from the page's server payload
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a6aff2ea2f
commit
68a3858355
3 files changed
+327
No files matched your search
@@ -0,0 +1,148 @@
|
||||
"""Deel: `deel:<slug>` for jobs.deel.com/<slug>, the whole board in one HTML
|
||||
page.
|
||||
|
||||
Written from Klarna's board on 2026-09-29. Deel's job board is a Next.js page
|
||||
with no public JSON endpoint (its `/api/` is disallowed by robots.txt), but
|
||||
the server-rendered page carries the board in its React Server Components
|
||||
payload: a stream of `self.__next_f.push([1, "..."])` scripts whose strings,
|
||||
joined, hold `"jobPostings":[...]` with every open role, and, beside it, the
|
||||
rich-text descriptions as separate text rows that a posting names by
|
||||
reference (`"richtextDescription":"$1a"`). Klarna's 96 roles came in one
|
||||
page, the same 96 as the page's own JSON-LD list, so no description needs a
|
||||
read of the role's page.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import html
|
||||
import json
|
||||
import re
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from desk.sources import strip_html
|
||||
|
||||
from ._shared import Row, num, only, parse_dt, pay_line
|
||||
|
||||
NAME = "deel"
|
||||
LABEL = "Deel"
|
||||
KEEP_CASE = True # `jobs.deel.com/Klarna` is "Job Board Not Found", `/klarna` is the board
|
||||
PATTERNS = (
|
||||
# `/job-boards/<slug>` is the address Klarna's own site links to.
|
||||
r"jobs\.deel\.com/(?:job-boards/)?(?!job-boards\b)([A-Za-z0-9][A-Za-z0-9_-]*)",
|
||||
)
|
||||
|
||||
_HOST = "jobs.deel.com"
|
||||
|
||||
#: A slug is one path segment that starts with a letter or a digit, so `_next`
|
||||
#: and `.` never name a board.
|
||||
_SLUG = re.compile(r"[A-Za-z0-9][A-Za-z0-9_-]*")
|
||||
|
||||
#: One script of the payload, its JSON string literal captured. Kind 1 is
|
||||
#: the data; the others (`[0]`, `[2, ...]`) carry the bootstrap.
|
||||
_PUSH = re.compile(r'self\.__next_f\.push\(\[1,("(?:[^"\\]|\\.)*")\]\)')
|
||||
|
||||
#: One row of the joined stream: `<hex id>:` and then either `T<hex length>,`
|
||||
#: and that many bytes of text, or a line of JSON.
|
||||
_ROW = re.compile(rb"([0-9a-f]*):")
|
||||
_TEXT = re.compile(rb"T([0-9a-f]+),")
|
||||
|
||||
#: Deel's `workArrangementEnum` -> `store._remote`'s words.
|
||||
_REMOTE = {"ON_SITE": "onsite", "HYBRID": "hybrid", "REMOTE": "remote"}
|
||||
|
||||
|
||||
def slug_ok(slug: str) -> bool:
|
||||
return bool(_SLUG.fullmatch(slug))
|
||||
|
||||
|
||||
def allowed(slug: str) -> Callable[[str], bool]:
|
||||
return only(_HOST)
|
||||
|
||||
|
||||
def careers_url(slug: str) -> str:
|
||||
return f"https://{_HOST}/{slug}"
|
||||
|
||||
|
||||
def robots_page(slug: str) -> str:
|
||||
return careers_url(slug)
|
||||
|
||||
|
||||
def feed_url(slug: str) -> str:
|
||||
return careers_url(slug)
|
||||
|
||||
|
||||
def _stream(body: bytes) -> dict[str, str]:
|
||||
"""The payload's rows by id. A text row's length is in bytes of UTF-8 and
|
||||
the next row follows it directly, so the stream is read as bytes, one row
|
||||
after another, rather than split on newlines."""
|
||||
text = "".join(json.loads(m.group(1)) for m in _PUSH.finditer(body.decode("utf-8", "replace")))
|
||||
data = text.encode()
|
||||
out: dict[str, str] = {}
|
||||
pos = 0
|
||||
while pos < len(data) and (row := _ROW.match(data, pos)):
|
||||
pos = row.end()
|
||||
if data[pos:pos + 1] == b"T" and (size := _TEXT.match(data, pos)):
|
||||
end = size.end() + int(size.group(1), 16)
|
||||
out[row.group(1).decode()] = data[size.end():end].decode("utf-8", "replace")
|
||||
pos = end
|
||||
else:
|
||||
end = data.find(b"\n", pos)
|
||||
end = len(data) if end < 0 else end
|
||||
out[row.group(1).decode()] = data[pos:end].decode("utf-8", "replace")
|
||||
pos = end + 1
|
||||
return out
|
||||
|
||||
|
||||
def _postings(body: bytes) -> tuple[list[dict[str, Any]], dict[str, str]]:
|
||||
"""The board's postings and the stream they refer into. A page without
|
||||
the postings array is not a board (a slug Deel does not know answers
|
||||
"Job Board Not Found"), and raises rather than read as an empty board."""
|
||||
stream = _stream(body)
|
||||
for value in stream.values():
|
||||
start = value.find('"jobPostings":[')
|
||||
if start >= 0:
|
||||
postings, _end = json.JSONDecoder().raw_decode(value[start + len('"jobPostings":'):])
|
||||
return postings, stream
|
||||
raise ValueError("not a Deel job board: no jobPostings in the page")
|
||||
|
||||
|
||||
def parse(body: bytes, slug: str) -> list[Row]:
|
||||
"""`jobs.deel.com/<slug>` -> one row per posting. `location` joins the
|
||||
role's places with "; ". `posted` is the day the posting was published
|
||||
(its publication's state), not the day the role was drafted.
|
||||
|
||||
Deel states pay as a currency and two amounts with no period, and the
|
||||
amounts run from 775,398 SEK to 55,206 SEK on one board, the latter
|
||||
plainly a month's pay. A yearly figure cannot be told from a monthly one,
|
||||
so the columns stay empty and `salary_text` gives the range as stated."""
|
||||
postings, stream = _postings(body)
|
||||
out = []
|
||||
for p in postings:
|
||||
title = (p.get("title") or "").strip()
|
||||
post_id = str(p.get("id") or "")
|
||||
if not title or not post_id:
|
||||
continue
|
||||
job = p.get("job") or {}
|
||||
places = [name for loc in job.get("jobLocations") or []
|
||||
if (name := ((loc.get("location") or {}).get("name") or "").strip())]
|
||||
departments = [name for d in job.get("jobDepartments") or []
|
||||
if (name := ((d.get("department") or {}).get("name") or "").strip())]
|
||||
pay = job.get("currentCompensation") or {}
|
||||
published = ((p.get("jobPostingPublications") or [{}])[0].get("currentState") or {})
|
||||
description = p.get("richtextDescription") or ""
|
||||
if description.startswith("$"):
|
||||
description = stream.get(description[1:], "")
|
||||
out.append({
|
||||
"source_id": post_id,
|
||||
"title": title,
|
||||
"location": "; ".join(dict.fromkeys(places)),
|
||||
"url": f"https://{_HOST}/{slug}/job-details/{post_id}/overview",
|
||||
"posted": parse_dt(published.get("createdAt") or p.get("createdAt")),
|
||||
"department": ", ".join(dict.fromkeys(departments)),
|
||||
"description": html.unescape(strip_html(description)),
|
||||
"remote": _REMOTE.get(str(job.get("workArrangementEnum") or "")),
|
||||
"salary_text": (pay_line(num(pay.get("minAmount")), num(pay.get("maxAmount")),
|
||||
pay.get("currencyIsoCode"), "")
|
||||
if p.get("isCompensationVisible") else ""),
|
||||
})
|
||||
return out
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>Klarna Careers</title></head><body><div id="root"></div>
|
||||
<script>self.__next_f.push([0])</script>
|
||||
<script>self.__next_f.push([1,"20:T365,<h2><strong>Klarna, briefly</strong></h2><p>At Klarna, we're building an everyday finance network, helping over 120 million consumers across 26 countries save time and money, and worry less about their finances. Working here means taking on problems most companies never get to solve, and being hands-on enough that the interesting part of the work lands with you, not someone else, you'll build with AI, not watch it happen.</p><p></p><p>This is the stretch zone. Come find out what you're capable of.</p><h2><strong>About the role</strong></h2><p>When Klarna's systems or security posture come under real pressure, someone has to take charge of the response in real time - coordinating the right technical teams, keeping decisions moving, and closing the loop with senior stakeholders instead of letting action items stall. That's what this position exists to do.</p>21:T21,<p><strong>About the position</p>22:T340,<p><strong>Klarna, briefly</strong></p><p>At Klarna, we're building an everyday finance network, helping over 120 million consumers across 26 countries save time and money, and worry less about their finances. Working here means taking on problems most companies never get to solve, and being hands-on enough that the interesting part of the work lands with you, not someone else, you'll build with AI, not watch it happen.</p><p>This is the stretch zone. Come find out what you're capable of.</p><p></p><p><strong>About the role</strong></p><p>Some customer cases aren't simple, a payment dispute needs untangling, an account question needs real judgment, a pattern needs to be flagged before it turns into ten more tickets. That work sits with Klarna's Customer Trust & Experience team, and it's what this position covers.</p>23:T380,<p><strong>Klarna, briefly</strong></p><p>At Klarna, we're building an everyday finance network, helping over 120 million consumers across 26 countries save time and money, and worry less about their finances. Working here means taking on problems most companies never get to solve, and being hands-on enough that the interesting part of the work lands with you, not someone else — you'll build with AI, not watch it happen.</p><p>This is the stretch zone. Come find out what you're capable of.</p><p></p><p></p><p><strong>About the role</strong></p><p>The Secure Development team equips Klarna's engineers to design, build, and deliver secure software through standardized tools and processes, continuous learning, and a security-focused engineering culture. As a Lead Engineer on the team, you'll work on preventing security flaws before they reach production, not cleaning them up after.</p>24:T314,<p><strong>Klarna, briefly</strong></p><p>At Klarna, we're building an everyday finance network, helping over 120 million consumers across 26 countries save time and money, and worry less about their finances. Working here means taking on problems most companies never get to solve, and being hands-on enough that the interesting part of the work lands with you, not someone else — you'll build with AI, not watch it happen.</p><p>This is the stretch zone. Come find out what you're capable of.</p><p><strong>About the role</strong></p><p>Every payment, login, and stored card in Klarna's iOS and Android apps depends on mobile-specific protections holding up — sandboxing, permission models, anti-tampering — and someone has to attack them before someone else does. That's you.</p>5:[\"$\",\"div\",null,{\"jobPostings\":[{\"id\":\"21584046-56d5-44c4-8b18-7e15dc659827\",\"jobId\":\"f9740e2a-e19c-4674-ac84-f6c200f6a713\",\"title\":\"Incident Manager\",\"richtextDescription\":\"$20\",\"applicationFormId\":\"0877b7a6-6b23-43b8-8002-f881005d4918\",\"isCompensationVisible\":true,\"createdAt\":\"2026-09-07T12:27:01.452Z\",\"updatedAt\":\"2026-09-09T07:09:42.074Z\",\"job\":{\"id\":\"f97"])</script>
|
||||
<script>self.__next_f.push([1,"40e2a-e19c-4674-ac84-f6c200f6a713\",\"workArrangementEnum\":\"ON_SITE\",\"jobEmploymentTypes\":[{\"id\":\"ca91fc4a-eb82-46c5-a171-cc50fa592436\",\"employmentType\":{\"id\":\"62e0c8ef-78c9-4cc8-ae0a-2930c60b6271\",\"name\":\"Full-time\"}}],\"jobLocations\":[{\"id\":\"fb39f226-9f16-4458-86b1-2da0bfd84030\",\"location\":{\"id\":\"39d5aaa0-6e90-48e5-8c98-14c04a7c34ca\",\"name\":\"Stockholm\"}}],\"currentCompensation\":{\"id\":\"37af691b-c172-4347-82cd-706045c098b6\",\"currencyIsoCode\":\"SEK\",\"minAmount\":775398,\"maxAmount\":1108832},\"tags\":[],\"jobTeams\":[{\"id\":\"bcca1eb3-4e74-4d11-a729-f64390d6d518\",\"team\":{\"id\":\"8c9d80d6-70f2-4a98-8388-46e4e3c02a47\",\"name\":\"Engineering\"}}],\"jobDepartments\":[{\"id\":\"3eb1563e-9a47-4230-90e5-6b70655b4b32\",\"department\":{\"id\":\"ae2801c1-dea4-4f1c-aaec-a00d678dd005\",\"name\":\"Engineering\"}}]},\"jobPostingPublications\":[{\"id\":\"34787ccf-3b72-4002-87fc-858d5ecbc0c4\",\"currentState\":{\"id\":\"d2ea4fdd-7f64-4744-b438-ab3496da141d\",\"stateSlug\":\"published_basic\",\"createdByHrisOrganizationUserId\":\"b8fe15d6-a262-4eb5-98cf-65ae5e866d97\",\"errorMessage\":null,\"createdAt\":\"2026-09-07T12:33:38.484Z\"},\"jobBoard\":{\"id\":\"c12332fe-4f66-4d3e-9941-156ddeacf0dc\"}}]},{\"id\":\"a66b42b6-eda9-4184-ad67-0601d14a9375\",\"jobId\":\"3f9527a4-60d2-4c14-b098-9676d888404b\",\"title\":\"Workforce Management Lead - Fincrime Operations\",\"richtextDescription\":\"$21\",\"applicationFormId\":\"0877b7a6-6b23-43b8-8002-f881005d4918\",\"isCompensationVisible\":true,\"createdAt\":\"2026-09-07T16:17:10.087Z\",\"updatedAt\":\"2026-09-07T16:17:10.087Z\",\"job\":{\"id\":\"3f9527a4-60d2-4c14-b098-9676d888404b\",\"workArrangementEnum\":\"ON_SITE\",\"jobEmploymentTypes\":[{\"id\":\"1ecf4a71-6353-4815-b917-6bbeb392dabc\",\"employmentType\":{\"id\":\"62e0c8ef-78c9-4cc8-ae0a-2930c60b6271\",\"name\":\"Full-time\"}}],\"jobLocations\":[{\"id\":\"ff0c5113-c7dc-4633-988f-a029ff50251b\",\"location\":{\"id\":\"91b000b1-6da9-44e5-af7b-26978f343d94\",\"name\":\"London\"}}],\"currentCompensation\":{\"id\":\"403661d6-7cf8-491b-968e-da7a508443ce\",\"currencyIsoCode\":\"GBP\",\"minAmount\":105197,\"maxAmount\":null},\"tags\":[],\"jobTeams\":[],\"jobDepartments\":[{\"id\":\"e97b8c54-d137-4e58-98c0-a87351d68d7e\",\"department\":{\"id\":\"c92b3787-be1b-4c03-bae4-7eb2d846d8d5\",\"name\":\"Business Operations\"}}]},\"jobPostingPublications\":[{\"id\":\"644e5928-e7a9-4bd7-a8a4-00deac2b798e\",\"currentState\":{\"id\":\"6f91ce37-9c0f-4cec-bda2-1c85d0144040\",\"stateSlug\":\"published_basic\",\"createdByHrisOrganizationUserId\":\"8963fdb9-9da3-4121-a5b7-1f2954ef8acb\",\"errorMessage\":null,\"createdAt\":\"2026-09-07T16:19:17.990Z\"},\"jobBoard\":{\"id\":\"c12332fe-4f66-4d3e-9941-156ddeacf0dc\"}}]},{\"id\":\"f96bb9d4-7a81-4e1e-be01-76c643eb6cb3\",\"jobId\":\"1734819d-d38e-425b-97a0-fcbeee1cb981\",\"title\":\"Customer Trust and Experience Agent (Fully Remote - Ohio) - Business Operations\",\"richtextDescription\":\"$22\",\"applicationFormId\":\"741ad1fc-6325-4c82-bec4-0919a40256cd\",\"isCompensationVisible\":false,\"createdAt\":\"2026-08-28T05:32:40.645Z\",\"updatedAt\":\"2026-09-17T13:14:24.329Z\",\"job\":{\"id\":\"1734819d-d38e-425b-97a0-fcbeee1cb981\",\"workArrangementEnum\":\"REMOTE\",\"jobEmploymentTypes\":[{\"id\":\"d7ecac74-0f15-43f5-abc1-045c1cb1debd\",\"employmentType\":{\"id\":\"209bdf13-fe8a-44ef-ae53-2f39265470ae\",\"name\":\"Consultant\"}}],\"jobLocations\":[{\"id\":\"dc918550-918d-4fce-8c70-dd6e2ef2e65f\",\"location\":{\"id\":\"a30feacc-5939-4622-b9e8-fe240bcaea9d\",\"name\":\"Ohio\"}}],\"currentCompensation\":null,\"tags\":[],\"jobTeams\":[{\"id\":\"733c5efb-71d7-42dd-890f-525a972f7dcf\",\"team\":{\"id\":\"c5f402cd-2f59-4d57-a6f2-d5542c41c656\",\"name\":\"Always Human\"}}],\"jobDepartments\":[{\"id\":\"44e383d7-9403-43e0-a751-b99bae9ccc0f\",\"department\":{\"id\":\"c92b3787-be1b-4c03-bae4-7eb2d846d8d5\",\"name\":\"Business Operations\"}}]},\"jobPostingPublications\":[{\"id\":\"d84ef0ae-8ec4-40f4-bb90-9ac1127a924c\",\"currentState\":{\"id\":\"835516dd-04cb-4137-ae2d-ee82e97fd3be\",\"stateSlug\":\"published_basic\",\"createdByHrisOrganizationUserId\":\"a139eb3c-8a7f-42a6-ac85-243776a0959a\",\"err"])</script>
|
||||
<script>self.__next_f.push([1,"orMessage\":null,\"createdAt\":\"2026-09-17T13:36:34.901Z\"},\"jobBoard\":{\"id\":\"c12332fe-4f66-4d3e-9941-156ddeacf0dc\"}}]},{\"id\":\"a8be45ac-b342-4be6-97af-ad2dd40b8479\",\"jobId\":\"14575daf-d794-44c0-8912-be34b80f809b\",\"title\":\"Lead Engineer — Application Security\",\"richtextDescription\":\"$23\",\"applicationFormId\":\"0877b7a6-6b23-43b8-8002-f881005d4918\",\"isCompensationVisible\":true,\"createdAt\":\"2026-08-28T08:15:13.007Z\",\"updatedAt\":\"2026-08-28T08:15:55.528Z\",\"job\":{\"id\":\"14575daf-d794-44c0-8912-be34b80f809b\",\"workArrangementEnum\":\"ON_SITE\",\"jobEmploymentTypes\":[{\"id\":\"25c78c72-12c9-4e89-84b0-e6a500e137b0\",\"employmentType\":{\"id\":\"62e0c8ef-78c9-4cc8-ae0a-2930c60b6271\",\"name\":\"Full-time\"}}],\"jobLocations\":[{\"id\":\"154a2fda-f232-45af-a5ae-be40153bcebc\",\"location\":{\"id\":\"39d5aaa0-6e90-48e5-8c98-14c04a7c34ca\",\"name\":\"Stockholm\"}},{\"id\":\"497b28a2-a723-488b-b216-e8c24b7196fe\",\"location\":{\"id\":\"91b000b1-6da9-44e5-af7b-26978f343d94\",\"name\":\"London\"}},{\"id\":\"b0530362-2136-4ba7-b552-1bf1fbe027d0\",\"location\":{\"id\":\"cfc33a04-4d3d-43d8-b36a-52550122d202\",\"name\":\"Milan\"}},{\"id\":\"129b9b2d-d039-4bbc-a0b4-79fde3bdcaf5\",\"location\":{\"id\":\"a31765f7-f872-404d-8abe-cc6075c47a1a\",\"name\":\"Warsaw\"}}],\"currentCompensation\":{\"id\":\"886da8d9-151d-41ba-915f-f0bec8555c00\",\"currencyIsoCode\":\"GBP\",\"minAmount\":91196,\"maxAmount\":116438},\"tags\":[],\"jobTeams\":[{\"id\":\"8ba298cd-9a19-486a-9114-9856ac72a0e7\",\"team\":{\"id\":\"8c9d80d6-70f2-4a98-8388-46e4e3c02a47\",\"name\":\"Engineering\"}}],\"jobDepartments\":[{\"id\":\"11635e3e-7c9d-4d3c-9448-54c24e9d9bb9\",\"department\":{\"id\":\"ae2801c1-dea4-4f1c-aaec-a00d678dd005\",\"name\":\"Engineering\"}}]},\"jobPostingPublications\":[{\"id\":\"efd1b98f-106b-4f28-907e-5f74ca5f9f96\",\"currentState\":{\"id\":\"3538ebd8-71aa-4047-8465-f65dd0590bfa\",\"stateSlug\":\"published_basic\",\"createdByHrisOrganizationUserId\":\"34023377-76e3-4853-a827-4d79fbb1a997\",\"errorMessage\":null,\"createdAt\":\"2026-08-28T08:25:01.991Z\"},\"jobBoard\":{\"id\":\"c12332fe-4f66-4d3e-9941-156ddeacf0dc\"}}]},{\"id\":\"a6649d86-1584-464a-b5bf-42457115df2f\",\"jobId\":\"ef1106d9-e2b7-4b76-9b13-bfb8e684d21b\",\"title\":\"Mobile Application Senior Security Engineer\",\"richtextDescription\":\"$24\",\"applicationFormId\":\"0877b7a6-6b23-43b8-8002-f881005d4918\",\"isCompensationVisible\":true,\"createdAt\":\"2026-08-26T13:17:25.890Z\",\"updatedAt\":\"2026-08-26T13:17:25.890Z\",\"job\":{\"id\":\"ef1106d9-e2b7-4b76-9b13-bfb8e684d21b\",\"workArrangementEnum\":\"ON_SITE\",\"jobEmploymentTypes\":[{\"id\":\"9cd3d4a4-969b-4e53-af20-a57eb5652ea6\",\"employmentType\":{\"id\":\"62e0c8ef-78c9-4cc8-ae0a-2930c60b6271\",\"name\":\"Full-time\"}}],\"jobLocations\":[{\"id\":\"e65f2062-92f6-4749-ad2c-f591a7641e7b\",\"location\":{\"id\":\"91b000b1-6da9-44e5-af7b-26978f343d94\",\"name\":\"London\"}},{\"id\":\"ec0540f0-7d51-4cc5-bb2c-d101abaff615\",\"location\":{\"id\":\"cfc33a04-4d3d-43d8-b36a-52550122d202\",\"name\":\"Milan\"}},{\"id\":\"70a36b00-f548-4276-8839-f2c666d659fb\",\"location\":{\"id\":\"39d5aaa0-6e90-48e5-8c98-14c04a7c34ca\",\"name\":\"Stockholm\"}},{\"id\":\"9b7e878d-718c-496f-ba3a-aa22d7744dbc\",\"location\":{\"id\":\"a31765f7-f872-404d-8abe-cc6075c47a1a\",\"name\":\"Warsaw\"}}],\"currentCompensation\":{\"id\":\"58771905-8f5c-4f47-b859-8c265cadb19e\",\"currencyIsoCode\":\"GBP\",\"minAmount\":91196,\"maxAmount\":116438},\"tags\":[],\"jobTeams\":[{\"id\":\"818c8081-5baa-40dd-a00d-2da2b9828c49\",\"team\":{\"id\":\"8c9d80d6-70f2-4a98-8388-46e4e3c02a47\",\"name\":\"Engineering\"}}],\"jobDepartments\":[{\"id\":\"82dfa249-8ab8-4847-ad67-8c7ba565dde5\",\"department\":{\"id\":\"ae2801c1-dea4-4f1c-aaec-a00d678dd005\",\"name\":\"Engineering\"}}]},\"jobPostingPublications\":[{\"id\":\"79fcf3a0-15d9-4a6a-b807-35d07cc1da39\",\"currentState\":{\"id\":\"01ef255c-3db1-4a47-af63-3e8161413c12\",\"stateSlug\":\"published_basic\",\"createdByHrisOrganizationUserId\":\"34023377-76e3-4853-a827-4d79fbb1a997\",\"errorMessage\":null,\"createdAt\":\"2026-08-26T13:49:29.953Z\"},\"jobBoard\":{\"id\":\"c12332fe-4f66-4d3e-9941-156ddeacf0dc\"}}]}],\"orgSlug\":\"klarna\"}]\n"])</script>
|
||||
</body></html>
|
||||
@@ -0,0 +1,173 @@
|
||||
"""The Deel host module against a saved page (trimmed from Klarna's board,
|
||||
2026-09-29), and the fetch around it. No network."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
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 deel # noqa: E402
|
||||
|
||||
PAGE = (ROOT / "tests" / "fixtures" / "ats" / "deel.html").read_bytes()
|
||||
URL = "https://jobs.deel.com/klarna"
|
||||
|
||||
|
||||
def test_rows_come_from_the_payload_with_descriptions_resolved() -> None:
|
||||
rows = deel.parse(PAGE, "klarna")
|
||||
assert [r["source_id"][:8] for r in rows] == [
|
||||
"21584046", "a66b42b6", "f96bb9d4", "a8be45ac", "a6649d86"]
|
||||
first = rows[0]
|
||||
assert first["title"] == "Incident Manager"
|
||||
assert first["url"] == ("https://jobs.deel.com/klarna/job-details/"
|
||||
"21584046-56d5-44c4-8b18-7e15dc659827/overview")
|
||||
assert first["location"] == "Stockholm" and first["department"] == "Engineering"
|
||||
assert first["remote"] == "onsite"
|
||||
assert first["description"].startswith("Klarna, briefly At Klarna")
|
||||
assert "<" not in first["description"] and "$" not in first["description"][:3]
|
||||
assert all(r["description"] for r in rows)
|
||||
# The day the posting was published, not the day it was drafted (12:27).
|
||||
assert first["posted"] is not None and first["posted"].isoformat() == \
|
||||
"2026-09-07T12:33:38.484000+00:00"
|
||||
|
||||
|
||||
def test_several_locations_are_joined_and_remote_uses_the_stores_words() -> None:
|
||||
rows = {r["source_id"][:8]: r for r in deel.parse(PAGE, "klarna")}
|
||||
assert rows["a8be45ac"]["location"] == "Stockholm; London; Milan; Warsaw"
|
||||
assert rows["f96bb9d4"]["remote"] == "remote"
|
||||
assert rows["f96bb9d4"]["location"] == "Ohio"
|
||||
|
||||
|
||||
def test_pay_is_only_text_since_the_period_is_not_stated() -> None:
|
||||
rows = {r["source_id"][:8]: r for r in deel.parse(PAGE, "klarna")}
|
||||
assert rows["21584046"]["salary_text"] == "SEK 775,398 to 1,108,832"
|
||||
assert rows["a66b42b6"]["salary_text"] == "GBP from 105,197"
|
||||
assert rows["f96bb9d4"]["salary_text"] == "" # a role with no range
|
||||
assert all("salary_min" not in r for r in rows.values())
|
||||
|
||||
|
||||
def _page_with(body: dict[str, Any]) -> bytes:
|
||||
"""A page whose one payload row holds `body`, and a description row of
|
||||
multibyte text whose length is given in bytes, as the stream does."""
|
||||
text = "Zo\u00eb\u2019s caf\u00e9 \u2014 100 \u20ac" # 2, 3 and 1 bytes wide
|
||||
row = f"5:T{len(text.encode()):x},{text}" + \
|
||||
'6:["$","div",null,' + json.dumps(body, ensure_ascii=False, separators=(",", ":")) + "]\n"
|
||||
return f'<script>self.__next_f.push([1,{json.dumps(row, ensure_ascii=False)}])</script>'.encode()
|
||||
|
||||
|
||||
def test_a_text_row_is_read_by_its_length_in_bytes() -> None:
|
||||
body = {"jobPostings": [{"id": "a", "title": "Baker", "richtextDescription": "$5",
|
||||
"job": {}}, {"id": "b", "title": "Cook",
|
||||
"richtextDescription": "<p>Inline & done</p>",
|
||||
"job": {}}]}
|
||||
rows = deel.parse(_page_with(body), "acme")
|
||||
assert [r["description"] for r in rows] == ["Zo\u00eb\u2019s caf\u00e9 \u2014 100 \u20ac",
|
||||
"Inline & done"]
|
||||
assert rows[0]["remote"] is None and rows[0]["location"] == "" and rows[0]["posted"] is None
|
||||
|
||||
|
||||
def test_a_board_without_roles_is_an_empty_board_but_another_page_is_not_a_board() -> None:
|
||||
assert deel.parse(_page_with({"jobPostings": []}), "acme") == []
|
||||
with pytest.raises(ValueError, match="not a Deel job board"):
|
||||
deel.parse(b"<html><title>Job Board Not Found</title></html>", "nobody")
|
||||
|
||||
|
||||
def test_a_posting_without_a_title_or_id_is_skipped() -> None:
|
||||
body = {"jobPostings": [{"id": "a", "title": " ", "job": {}}, {"title": "x", "job": {}},
|
||||
{"id": "c", "title": "Cook", "job": {}}]}
|
||||
assert [r["source_id"] for r in deel.parse(_page_with(body), "acme")] == ["c"]
|
||||
|
||||
|
||||
# ------------------------------------------------------------ the fetch
|
||||
|
||||
@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)
|
||||
return {"answers": answers, "asked": asked}
|
||||
|
||||
|
||||
def test_the_board_is_one_request_and_complete(web: dict[str, Any]) -> None:
|
||||
web["answers"][URL] = PAGE
|
||||
with httpx.Client() as client:
|
||||
rows, complete = ats._fetch_rows(client, "deel:klarna")
|
||||
assert len(rows) == 5 and complete
|
||||
assert web["asked"] == [URL]
|
||||
|
||||
|
||||
def test_a_page_that_cannot_be_read_fails_the_board(web: dict[str, Any]) -> None:
|
||||
web["answers"][URL] = b"<html>Job Board Not Found</html>"
|
||||
with httpx.Client() as client, pytest.raises(ValueError):
|
||||
ats._fetch_rows(client, "deel:klarna")
|
||||
|
||||
|
||||
# ------------------------------------------------------- slugs and hosts
|
||||
|
||||
def test_the_module_is_registered_as_a_feed_host() -> None:
|
||||
assert atshosts.HOSTS["deel"] is deel and ats.HOSTS["deel"] == "Deel"
|
||||
assert deel.NAME == "deel" and deel.KEEP_CASE
|
||||
assert not hasattr(deel, "page") and not hasattr(deel, "detail")
|
||||
|
||||
|
||||
def test_the_urls_and_the_robots_page_are_the_boards_own() -> None:
|
||||
assert deel.careers_url("klarna") == URL
|
||||
assert deel.feed_url("klarna") == URL
|
||||
assert deel.robots_page("klarna") == URL
|
||||
assert deel.allowed("klarna")("jobs.deel.com") and deel.allowed("klarna")("JOBS.DEEL.COM")
|
||||
for host in ("deel.com", "api.deel.com", "jobs.deel.com.evil.example", "evil.example"):
|
||||
assert not deel.allowed("klarna")(host)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("slug", ["klarna", "Klarna", "acme-2", "a_b", "9lives", "localhost"])
|
||||
def test_a_slug_is_one_path_segment(slug: str) -> None:
|
||||
"""`localhost` is only a path here: the host of every URL is fixed."""
|
||||
assert ats.is_known_target(f"deel:{slug}")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("slug", [
|
||||
"", "a@b", "a#b", "a?b", "..", ".", "a%2fb", "a/b", "a:443", "a b", "acme\n", " acme",
|
||||
"127.0.0.1", "a.b", "_next", "-x", "a\\b", "évil",
|
||||
])
|
||||
def test_a_hostile_slug_is_refused(slug: str) -> None:
|
||||
assert not deel.slug_ok(slug)
|
||||
assert not ats.is_known_target(f"deel:{slug}")
|
||||
|
||||
|
||||
def test_no_slug_reaches_another_host() -> None:
|
||||
"""The host is fixed in every URL the module builds; a slug only ever
|
||||
lands in the path."""
|
||||
for slug in ("klarna", "Klarna", "a-b_c"):
|
||||
for url in (deel.careers_url(slug), deel.feed_url(slug), deel.robots_page(slug)):
|
||||
assert httpx.URL(url).host == "jobs.deel.com"
|
||||
|
||||
|
||||
def test_discovery_finds_the_slug_in_a_career_site_url() -> None:
|
||||
page = ('<a href="https://jobs.deel.com/job-boards/klarna">All open positions</a>'
|
||||
'<a href="https://jobs.deel.com/acme/job-details/1/overview">Role</a>'
|
||||
'<a href="https://jobs.deel.com/Beta">Beta</a>'
|
||||
'<script src="https://jobs.deel.com/_next/static/x.js"></script>'
|
||||
'<a href="https://jobs.deel.com/job-boards">List</a>')
|
||||
assert [(h, s) for h, s, _ in boards_in(page)] == [
|
||||
("deel", "klarna"), ("deel", "acme"), ("deel", "Beta")]
|
||||
Reference in new issue
Block a user