-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rss_generic.py
More file actions
72 lines (56 loc) · 2.74 KB
/
Copy pathtest_rss_generic.py
File metadata and controls
72 lines (56 loc) · 2.74 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
"""rss_generic adapter tests (roadmap M4, ADR-0031)."""
from __future__ import annotations
from unittest.mock import patch
import pytest
from openjobradar.poll.adapters import rss_generic
from openjobradar.poll.http import HttpError
_JOB_FEED = """<?xml version="1.0"?>
<rss><channel>
<title>Acme Careers</title>
<link>https://acme.example/careers</link>
<item>
<title>Senior Engineer</title>
<link>https://acme.example/careers/1</link>
<guid>job-1</guid>
<description>Build things.</description>
<pubDate>Mon, 01 Jan 2026 00:00:00 GMT</pubDate>
</item>
</channel></rss>"""
_BLOG_FEED = """<?xml version="1.0"?>
<rss><channel>
<title>Acme Blog</title>
<link>https://acme.example/blog</link>
<item><title>5 Tips for Onboarding</title><link>https://acme.example/blog/1</link></item>
</channel></rss>"""
def test_parses_job_feed_into_postings() -> None:
with patch("openjobradar.poll.adapters.rss_generic.is_public_http_url", return_value=True), patch(
"openjobradar.poll.adapters.rss_generic.get_text", return_value=(200, _JOB_FEED)
):
postings = rss_generic.list_postings("https://acme.example/careers/feed", "acme", "Acme")
assert len(postings) == 1
posting = postings[0]
assert posting.job_id == "job-1"
assert posting.title == "Senior Engineer"
assert posting.jd_text == "Build things."
def test_rejects_non_job_feed() -> None:
with patch("openjobradar.poll.adapters.rss_generic.is_public_http_url", return_value=True), patch(
"openjobradar.poll.adapters.rss_generic.get_text", return_value=(200, _BLOG_FEED)
):
assert rss_generic.list_postings("https://acme.example/blog/feed", "acme", "Acme") == []
def test_raises_on_error_status() -> None:
with patch("openjobradar.poll.adapters.rss_generic.is_public_http_url", return_value=True), patch(
"openjobradar.poll.adapters.rss_generic.get_text", return_value=(404, "")
), pytest.raises(HttpError):
rss_generic.list_postings("https://acme.example/careers/feed", "acme", "Acme")
def test_trusted_feed_skips_job_feed_heuristic() -> None:
with patch("openjobradar.poll.adapters.rss_generic.is_public_http_url", return_value=True), patch(
"openjobradar.poll.adapters.rss_generic.get_text", return_value=(200, _BLOG_FEED)
):
postings = rss_generic.postings_from_feed(
"https://acme.example/blog/feed", "acme", "Acme", ats_type="teamtailor", trusted=True
)
assert len(postings) == 1
assert postings[0].ats_type == "teamtailor"
def test_blocked_url_returns_empty() -> None:
with patch("openjobradar.poll.adapters.rss_generic.is_public_http_url", return_value=False):
assert rss_generic.list_postings("https://169.254.169.254/feed", "acme", "Acme") == []