-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_render.py
More file actions
93 lines (71 loc) · 3.85 KB
/
Copy pathtest_render.py
File metadata and controls
93 lines (71 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Playwright render-scraper tests (roadmap M4, ADR-0031).
`scrape()` itself drives a real headless browser and is marked `# pragma: no cover`, matching the
source repo's own convention — it isn't unit-testable without Playwright installed and a real (or
mocked-at-the-protocol-level) browser. What's tested here is every pure function it composes:
JSON-LD extraction, the Darwinbox card mapper, the Google-for-Jobs host check, and the LLM
extractor's grounding/filtering logic (with the Bedrock call itself mocked).
"""
from __future__ import annotations
from unittest.mock import patch
from openjobradar.poll import render
def test_from_jsonld_extracts_job_postings() -> None:
blocks = [
{
"@type": "JobPosting",
"title": "Senior Engineer",
"description": "<p>Build things.</p>",
"url": "https://acme.example/jobs/1",
"jobLocation": {"address": {"addressLocality": "Remote", "addressRegion": "US"}},
"datePosted": "2026-01-01",
}
]
postings = render._from_jsonld(blocks, "acme", "Acme", "https://acme.example/careers")
assert len(postings) == 1
assert postings[0].title == "Senior Engineer"
assert postings[0].jd_text == "Build things."
assert postings[0].location_raw == "Remote, US"
def test_from_jsonld_ignores_non_jobposting_nodes() -> None:
assert render._from_jsonld([{"@type": "Organization"}], "acme", "Acme", "https://acme.example") == []
def test_darwinbox_postings_extracts_job_id_from_href() -> None:
cards = [{"title": "Data Analyst", "location": "Remote", "href": "https://acme.darwinbox.com/careers/jobDetails/123"}]
postings = render._darwinbox_postings(cards, "acme", "Acme")
assert postings[0].job_id == "123"
assert postings[0].title == "Data Analyst"
def test_is_google_jobs_matches_any_google_cctld_with_job_marker() -> None:
assert render._is_google_jobs("https://www.google.com/search?q=jobs&ibp=htl;jobs")
assert render._is_google_jobs("https://www.google.co.uk/search?ibp=htl;jobs")
assert not render._is_google_jobs("https://board.example/?ref=google.com/ibp=htl")
assert not render._is_google_jobs("https://www.google.com/search?q=jobs")
def test_llm_extract_disabled_without_env_returns_empty() -> None:
with patch.dict("os.environ", {}, clear=True):
assert render._llm_extract("some text", [], "acme", "Acme", "https://acme.example") == []
def test_llm_extract_grounds_and_filters_generic_titles() -> None:
env = {"OPENJOBRADAR_LLM_EXTRACT": "1", "OPENJOBRADAR_LLM_EXTRACT_MODEL_ID": "anthropic.claude"}
fake_response = {
"content": [
{
"text": (
'[{"title": "Senior Engineer", "company": "Acme", '
'"apply_url": "https://acme.example/jobs/1", "location": "Remote"},'
'{"title": "View all jobs", "company": "Acme", '
'"apply_url": "https://acme.example/jobs", "location": ""}]'
)
}
]
}
class _FakeBody:
def read(self) -> bytes:
import json
return json.dumps(fake_response).encode()
class _FakeClient:
def invoke_model(self, **kwargs: object) -> dict:
return {"body": _FakeBody()}
with patch.dict("os.environ", env, clear=True), patch("boto3.client", return_value=_FakeClient()):
postings = render._llm_extract("page text", [], "acme", "Acme", "https://acme.example")
assert len(postings) == 1
assert postings[0].title == "Senior Engineer"
assert postings[0].org_name == "Acme"
def test_list_postings_delegates_to_scrape() -> None:
with patch("openjobradar.poll.render.scrape", return_value=[]) as scrape_mock:
render.list_postings("https://acme.example/careers", "acme", "Acme")
scrape_mock.assert_called_once_with("https://acme.example/careers", "acme", "Acme")