election-game/backend/data/pipeline/tests/people/test_people_network.py

40 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""連網測試:確認官方來源的格式沒有改變(預設不執行:pytest -m network)。"""
from __future__ import annotations
import json
from pathlib import Path
import pytest
from election_data.people.cabinet import parse_members
from election_data.people.candidates import CEC_ARTICLE_API, article_html, parse_press_release
from election_data.people.catalog import EY_AGENCY_HEADS
from election_data.people.downloads import fetch
from election_data.people.legislators import LY_ID9_URL, load_ly_json, parse_legislators
from election_data.people.mayors import MOI_BASE, parse_list
pytestmark = pytest.mark.network
def test_ly_id9_live(tmp_path: Path) -> None:
result = fetch(LY_ID9_URL, tmp_path / "id9.json")
claims = parse_legislators(load_ly_json(result.path), "ly")
assert sum(c.current for c in claims) >= 100
def test_moi_county_mayors_live(tmp_path: Path) -> None:
result = fetch(MOI_BASE + "LocalOfficial.aspx?n=579&TYP=KND0005&PageSize=50", tmp_path / "moi.html")
assert len(parse_list(result.path.read_text(encoding="utf-8"))) == 16
def test_ey_agency_heads_live(tmp_path: Path) -> None:
result = fetch(EY_AGENCY_HEADS.url, tmp_path / "ey.html")
assert len(parse_members(result.path.read_text(encoding="utf-8"))) >= 20
def test_cec_candidates_live(tmp_path: Path) -> None:
result = fetch(CEC_ARTICLE_API, tmp_path / "cec.json")
body, _ = article_html(json.loads(result.path.read_text(encoding="utf-8")))
assert len(parse_press_release(body, "cec")) == 81