83 lines
2.8 KiB
Python
83 lines
2.8 KiB
Python
from pathlib import Path
|
|
|
|
from job_research.models import ApecListing, ApecRunMeta, ApecSnapshotMeta, ListingWarning
|
|
from job_research.storage import apec_run_paths
|
|
|
|
|
|
FIXED_RUN_ID = "2026-06-01T10-00-00-123456Z"
|
|
|
|
|
|
def test_apec_models_serialize_expected_listing_shape() -> None:
|
|
listing = ApecListing(
|
|
source="apec",
|
|
source_job_id="123",
|
|
url="https://example.test/job/123",
|
|
title="Data Engineer",
|
|
company="Example",
|
|
location="Paris",
|
|
contract_type="CDI",
|
|
description_text="Build pipelines",
|
|
published_at="2026-06-01",
|
|
refreshed_at="2026-06-02",
|
|
fetched_at="2026-06-01T10:00:00Z",
|
|
warnings=[
|
|
ListingWarning(
|
|
field="location",
|
|
message="Location inferred from page text",
|
|
)
|
|
],
|
|
)
|
|
run_meta = ApecRunMeta(
|
|
run_id=FIXED_RUN_ID,
|
|
run_started_at="2026-06-01T10:00:00Z",
|
|
derived_queries=["Data Engineer"],
|
|
snapshots=[
|
|
ApecSnapshotMeta(
|
|
url="https://example.test/job/123",
|
|
source_job_id="123",
|
|
snapshot_file="job-123.html",
|
|
fetched_at="2026-06-01T10:00:00Z",
|
|
)
|
|
],
|
|
fetched_count=1,
|
|
normalized_count=1,
|
|
deduplicated_count=1,
|
|
failed_count=0,
|
|
listing_errors=[],
|
|
)
|
|
|
|
assert listing.model_dump()["source"] == "apec"
|
|
assert listing.model_dump()["warnings"][0]["field"] == "location"
|
|
assert listing.model_dump()["refreshed_at"] == "2026-06-02"
|
|
assert run_meta.model_dump()["run_id"] == FIXED_RUN_ID
|
|
assert run_meta.model_dump()["run_started_at"] == "2026-06-01T10:00:00Z"
|
|
assert run_meta.model_dump()["derived_queries"] == ["Data Engineer"]
|
|
assert run_meta.model_dump(mode="json")["snapshots"] == [
|
|
{
|
|
"url": "https://example.test/job/123",
|
|
"source_job_id": "123",
|
|
"snapshot_file": "job-123.html",
|
|
"fetched_at": "2026-06-01T10:00:00Z",
|
|
}
|
|
]
|
|
|
|
|
|
def test_apec_run_paths_builds_expected_layout(tmp_path: Path) -> None:
|
|
paths = apec_run_paths(tmp_path, run_id=FIXED_RUN_ID)
|
|
run_dir = tmp_path / "apec" / "runs" / FIXED_RUN_ID
|
|
|
|
assert paths["run_dir"] == run_dir
|
|
assert paths["listings"] == run_dir / "listings.yaml"
|
|
assert paths["run_meta"] == run_dir / "run-meta.yaml"
|
|
assert paths["snapshots"] == run_dir / "snapshots"
|
|
|
|
|
|
def test_apec_run_artifacts_include_snapshot_and_meta(tmp_path: Path) -> None:
|
|
paths = apec_run_paths(tmp_path, run_id=FIXED_RUN_ID)
|
|
paths["snapshots"].mkdir(parents=True, exist_ok=True)
|
|
|
|
snapshot = paths["snapshots"] / "job-123.html"
|
|
snapshot.write_text("<html>snapshot</html>", encoding="utf-8")
|
|
|
|
assert snapshot.read_text(encoding="utf-8") == "<html>snapshot</html>"
|