Model/tests/orchestration/test_build_canonical_filename.py
2026-06-15 11:11:08 +00:00

106 lines
2.9 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.

# scripts/tests/test_build_canonical_filename.py
from orchestration.sharepoint_renamer_orchestrator import build_canonical_filename
UPRN = "10093456789"
ADDRESS = "1 High Street, Anytown"
POSTCODE = "SW1A 1AA"
STREET = "1 High Street"
def test_already_renamed_returns_none() -> None:
# Arrange
original = f"{UPRN}_High Street SW1A 1AA_EPC Report.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result is None
def test_address_postcode_prefix_stripped() -> None:
# Arrange
original = f"{ADDRESS} {POSTCODE} - EPC Report.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result == f"{UPRN}_{STREET} {POSTCODE}_EPC Report.pdf"
def test_address_only_prefix_stripped() -> None:
# Arrange
original = f"{ADDRESS} - EPC Report.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result == f"{UPRN}_{STREET} {POSTCODE}_EPC Report.pdf"
def test_street_postcode_prefix_stripped() -> None:
# Arrange
original = f"{STREET} {POSTCODE} - EPC Report.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result == f"{UPRN}_{STREET} {POSTCODE}_EPC Report.pdf"
def test_street_only_prefix_stripped() -> None:
# Arrange
original = f"{STREET} - EPC Report.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result == f"{UPRN}_{STREET} {POSTCODE}_EPC Report.pdf"
def test_dash_separator_removed_after_prefix_strip() -> None:
# Arrange " - " separator between prefix and doc name
original = f"{STREET} {POSTCODE} - Floor Plan.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result == f"{UPRN}_{STREET} {POSTCODE}_Floor Plan.pdf"
def test_underscore_separator_removed_after_prefix_strip() -> None:
# Arrange " _ " separator between prefix and doc name
original = f"{STREET} {POSTCODE} _ Floor Plan.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result == f"{UPRN}_{STREET} {POSTCODE}_Floor Plan.pdf"
def test_no_recognised_prefix_preserves_stem() -> None:
# Arrange
original = "Completely Different Name.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result == f"{UPRN}_{STREET} {POSTCODE}_Completely Different Name.pdf"
def test_no_doc_name_after_strip_omits_trailing_separator() -> None:
# Arrange stem is exactly the address prefix with no trailing doc name
original = f"{STREET} {POSTCODE}.pdf"
# Act
result = build_canonical_filename(UPRN, ADDRESS, POSTCODE, original)
# Assert
assert result == f"{UPRN}_{STREET} {POSTCODE}.pdf"