-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_edjoin.py
More file actions
71 lines (56 loc) · 2.49 KB
/
Copy pathtest_edjoin.py
File metadata and controls
71 lines (56 loc) · 2.49 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
"""EDJOIN adapter tests (roadmap M4, ADR-0031)."""
from __future__ import annotations
from unittest.mock import patch
import pytest
from openjobradar.poll.adapters import edjoin
from openjobradar.poll.http import HttpError
_PAGE_1 = {
"totalRecords": 1,
"totalPages": 1,
"data": [
{
"postingID": "9001",
"positionTitle": "Elementary Teacher",
"city": "Example City",
"countyName": "Example County",
"jobType": "Certificated",
"salaryInfo": "$60,000 - $80,000",
"postingDate": "/Date(1767225600000)/",
}
],
}
_EMPTY_PAGE = {"totalRecords": 0, "totalPages": 1, "data": []}
def test_parses_representative_payload_into_postings() -> None:
with patch("openjobradar.poll.adapters.edjoin.get_json", return_value=_PAGE_1):
postings = edjoin.list_postings("100", "acme-usd", "Acme USD")
assert len(postings) == 1
posting = postings[0]
assert posting.org_slug == "acme-usd"
assert posting.ats_type == "edjoin"
assert posting.job_id == "9001"
assert posting.title == "Elementary Teacher"
assert "Example City" in posting.location_raw
assert "Salary: $60,000 - $80,000" in posting.jd_text
assert posting.apply_url == "https://www.edjoin.org/Home/JobPosting/9001"
def test_zero_records_with_real_district_returns_empty() -> None:
district_page_html = "var district = 'Acme Unified School District';"
with (
patch("openjobradar.poll.adapters.edjoin.get_json", return_value=_EMPTY_PAGE),
patch("openjobradar.poll.adapters.edjoin.get_text", return_value=(200, district_page_html)),
):
assert edjoin.list_postings("100", "acme-usd", "Acme USD") == []
def test_zero_records_with_unknown_district_raises() -> None:
with (
patch("openjobradar.poll.adapters.edjoin.get_json", return_value=_EMPTY_PAGE),
patch("openjobradar.poll.adapters.edjoin.get_text", return_value=(200, "var district = '';")),
pytest.raises(HttpError),
):
edjoin.list_postings("99999999", "acme-usd", "Acme USD")
def test_rejects_zero_and_non_numeric_district_ids() -> None:
with pytest.raises(ValueError):
edjoin.list_postings("0", "acme", "Acme")
with pytest.raises(ValueError):
edjoin.list_postings("not-a-number", "acme", "Acme")
def test_detect_extracts_district_id() -> None:
assert edjoin.detect("https://www.edjoin.org/Home/Jobs?districtID=100") == "100"
assert edjoin.detect("https://example.com") is None