orc-renaming/tests/test_normalize.py

56 lines
1.6 KiB
Python

from datetime import date
import pytest
from orc_renaming.models import DocumentScope, DocumentType, ExtractionResult
from orc_renaming.normalize import build_filename, sanitize_component
def test_sanitize_component() -> None:
assert sanitize_component(" Müller & Söhne GmbH ") == "Mueller-Soehne-GmbH"
def test_property_invoice_filename() -> None:
result = ExtractionResult(
document_type=DocumentType.INVOICE,
scope=DocumentScope.PROPERTY,
document_date=date(2026, 7, 18),
company="Stadtwerke Musterstadt",
property_id="WH1",
confidence=0.95,
)
assert build_filename(result) == "260718_RE_Stadtwerke-Musterstadt-WH1.pdf"
def test_private_invoice_filename() -> None:
result = ExtractionResult(
document_type=DocumentType.INVOICE,
scope=DocumentScope.PRIVATE,
document_date=date(2026, 7, 18),
company="Müller & Söhne",
confidence=0.95,
)
assert build_filename(result) == "260718_RE_Mueller-Soehne-priv.pdf"
def test_correspondence_filename() -> None:
result = ExtractionResult(
document_type=DocumentType.CORRESPONDENCE,
document_date=date(2026, 7, 18),
company="Versicherung AG",
topic="Änderung des Vertrags",
confidence=0.95,
)
assert build_filename(result) == "260718_Versicherung-AG-Aenderung-des-Vertrags.pdf"
def test_incomplete_invoice_is_rejected() -> None:
result = ExtractionResult(
document_type=DocumentType.INVOICE,
document_date=date(2026, 7, 18),
company="Firma",
)
with pytest.raises(ValueError, match="Zuordnung"):
build_filename(result)