Neue Tests in dieser Migration: - test_database.py (Merkliste-CRUD, Subscriptions, abgeordnetenwatch-Joins) - test_clustering.py (82% Coverage) - test_drucksache_typen.py (100%) - test_mail.py (86%) - test_monitoring.py (23 Tests) - test_abgeordnetenwatch.py (23 Tests, inkl. Drucksache-Extraction) - test_redline_parser.py (20 Tests fuer §INS§/§DEL§-Marker) - test_bug_regressions.py (PRAGMA, JWT-azp, CDU-PDF, PFLICHT-FRAKTIONEN, NRW-Titel) - test_embeddings_v3_v4.py (WRITE/READ-Pattern) - test_wahlprogramm_check.py (#128) - test_wahlprogramm_fetch.py (#138) - test_antrag/bewertung/abonnement_repository.py + test_llm_bewerter.py (DDD) - test_domain_behavior.py (5 Domain-Methoden boundary tests) - tests/e2e/test_ui.py (Playwright) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
70 lines
3.0 KiB
Python
70 lines
3.0 KiB
Python
"""Tests für wahlprogramm_check.py (#128) — Erkennung fehlender Wahlprogramme."""
|
|
import pytest
|
|
|
|
from app.wahlprogramm_check import check_missing_programmes
|
|
from app.wahlprogramme import WAHLPROGRAMME
|
|
from app.bundeslaender import BUNDESLAENDER
|
|
|
|
|
|
class TestCheckMissingProgrammes:
|
|
"""Einheitstests für check_missing_programmes()."""
|
|
|
|
def test_all_covered_returns_empty(self):
|
|
"""Alle Fraktionen haben ein hinterlegtes Programm → leere Liste."""
|
|
bl = "NRW"
|
|
# Nur Fraktionen übergeben, die in WAHLPROGRAMME["NRW"] liegen
|
|
indexed = list(WAHLPROGRAMME[bl].keys())
|
|
result = check_missing_programmes(bl, indexed)
|
|
assert result == [], (
|
|
f"Erwartet [], bekommen {result!r} — alle Fraktionen sollten abgedeckt sein"
|
|
)
|
|
|
|
def test_one_missing_fraktion(self):
|
|
"""Eine Fraktion ohne Programm → wird in der Rückgabe gemeldet."""
|
|
bl = "NRW"
|
|
# AfD ist in NRW hinterlegt, BSW nicht
|
|
fraktionen = list(WAHLPROGRAMME[bl].keys()) + ["BSW"]
|
|
result = check_missing_programmes(bl, fraktionen)
|
|
assert "BSW" in result
|
|
|
|
def test_small_party_never_indexed(self):
|
|
"""BSW/FREIE WÄHLER/SSW sind typischerweise nicht in WAHLPROGRAMME —
|
|
werden korrekt als fehlend gemeldet."""
|
|
bl = "NRW"
|
|
unindexed_parties = ["BSW", "FREIE WÄHLER", "PIRATEN"]
|
|
for partei in unindexed_parties:
|
|
result = check_missing_programmes(bl, [partei])
|
|
assert partei in result, (
|
|
f"{partei!r} sollte als fehlend erkannt werden, war aber nicht in {result!r}"
|
|
)
|
|
|
|
def test_empty_fraktionen_returns_empty(self):
|
|
"""Leere Fraktionsliste → immer leere Ausgabe, kein Fehler."""
|
|
result = check_missing_programmes("NRW", [])
|
|
assert result == []
|
|
|
|
def test_unknown_bundesland_raises_value_error(self):
|
|
"""Unbekanntes Bundesland → ValueError."""
|
|
with pytest.raises(ValueError, match="Unbekanntes Bundesland"):
|
|
check_missing_programmes("XX", ["CDU"])
|
|
|
|
def test_bundesland_without_wahlprogramme_entry(self):
|
|
"""Aktives Bundesland ohne WAHLPROGRAMME-Eintrag → alle Fraktionen fehlend."""
|
|
# Finde ein aktives BL, das keinen Eintrag in WAHLPROGRAMME hat
|
|
bl_without = next(
|
|
(code for code in BUNDESLAENDER if code not in WAHLPROGRAMME),
|
|
None,
|
|
)
|
|
if bl_without is None:
|
|
pytest.skip("Alle bekannten Bundesländer haben WAHLPROGRAMME-Einträge")
|
|
fraktionen = BUNDESLAENDER[bl_without].landtagsfraktionen[:2]
|
|
result = check_missing_programmes(bl_without, fraktionen)
|
|
assert result == fraktionen
|
|
|
|
def test_result_preserves_order(self):
|
|
"""Die Reihenfolge der fehlenden Fraktionen entspricht der Input-Reihenfolge."""
|
|
bl = "NRW"
|
|
missing_input = ["BSW", "FREIE WÄHLER", "PIRATEN"]
|
|
result = check_missing_programmes(bl, missing_input)
|
|
assert result == missing_input
|