From 95b17a7c508bf89a121e2a01589131a48852b7fe Mon Sep 17 00:00:00 2001 From: Antoine Date: Mon, 1 Jun 2026 13:30:33 +0200 Subject: [PATCH] fix: preserve Apec listing metadata --- src/job_research/apec/normalize.py | 19 ++++++++++++++----- tests/apec/test_normalize.py | 8 ++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/job_research/apec/normalize.py b/src/job_research/apec/normalize.py index 56b6553..b503798 100644 --- a/src/job_research/apec/normalize.py +++ b/src/job_research/apec/normalize.py @@ -3,7 +3,14 @@ from bs4 import BeautifulSoup from job_research.models import ApecListing -def normalize_apec_listing(url: str, html: str, fetched_at: str) -> ApecListing: +def normalize_apec_listing( + url: str, + html: str, + fetched_at: str, + *, + source_job_id: str | None = None, + published_at: str | None = None, +) -> ApecListing: soup = BeautifulSoup(html, "html.parser") title = soup.find("h1") @@ -14,11 +21,13 @@ def normalize_apec_listing(url: str, html: str, fetched_at: str) -> ApecListing: return ApecListing( source="apec", + source_job_id=source_job_id, url=url, - title=title.get_text(strip=True) if title else None, - company=company.get_text(strip=True) if company else None, - location=location.get_text(strip=True) if location else None, - contract_type=contract.get_text(strip=True) if contract else None, + title=title.get_text(" ", strip=True) if title else None, + company=company.get_text(" ", strip=True) if company else None, + location=location.get_text(" ", strip=True) if location else None, + contract_type=contract.get_text(" ", strip=True) if contract else None, description_text=description.get_text(" ", strip=True) if description else None, + published_at=published_at, fetched_at=fetched_at, ) diff --git a/tests/apec/test_normalize.py b/tests/apec/test_normalize.py index b20090a..69a9141 100644 --- a/tests/apec/test_normalize.py +++ b/tests/apec/test_normalize.py @@ -5,8 +5,8 @@ def test_normalize_apec_listing_extracts_minimal_shape() -> None: html = """ -

Data Engineer

-
Example Corp
+

Data Engineer

+
Example Corp
Paris
CDI
Build pipelines
@@ -18,13 +18,17 @@ def test_normalize_apec_listing_extracts_minimal_shape() -> None: url="https://example.test/job/123", html=html, fetched_at="2026-06-01T10:00:00Z", + source_job_id="job-123", + published_at="2026-05-31", ) assert listing.source == "apec" + assert listing.source_job_id == "job-123" assert listing.url == "https://example.test/job/123" assert listing.title == "Data Engineer" assert listing.company == "Example Corp" assert listing.location == "Paris" assert listing.contract_type == "CDI" assert listing.description_text == "Build pipelines" + assert listing.published_at == "2026-05-31" assert listing.fetched_at == "2026-06-01T10:00:00Z"