mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Renamer finds properties filed under _Sero Batch roots 🟥
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
a442dcfbaa
commit
ab8b8decb3
1 changed files with 47 additions and 0 deletions
|
|
@ -1,15 +1,32 @@
|
|||
from pathlib import Path
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from backend.pashub_fetcher.sharepoint_subfolders import SharepointSubfolders
|
||||
from orchestration.sharepoint_renamer_orchestrator import (
|
||||
ASSESSMENT_SUBFOLDER,
|
||||
BASE_PATH,
|
||||
SharepointRenamerOrchestrator,
|
||||
build_canonical_filename,
|
||||
)
|
||||
|
||||
|
||||
def _assessment_path(root: str, address: str, postcode: str) -> str:
|
||||
return (
|
||||
f"{root}/{address}, {postcode}"
|
||||
f"/{SharepointSubfolders.ASSESSMENT.value}/{ASSESSMENT_SUBFOLDER}"
|
||||
)
|
||||
|
||||
|
||||
def _write_csv(tmp_path: Path, rows: list[tuple[str, str, str]]) -> str:
|
||||
lines = ["UPRN,Address,Postcode"] + [",".join(row) for row in rows]
|
||||
csv_file = tmp_path / "addresses.csv"
|
||||
csv_file.write_text("\n".join(lines) + "\n", encoding="utf-8")
|
||||
return str(csv_file)
|
||||
|
||||
|
||||
def _make_file(name: str, item_id: str = "id-1") -> dict[str, Any]:
|
||||
return {"name": name, "id": item_id, "file": {}}
|
||||
|
||||
|
|
@ -77,6 +94,36 @@ def test_discover_roots_includes_sero_batch_folders() -> None:
|
|||
sp.get_folders_in_path.assert_called_once_with(BASE_PATH)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# run — properties under a batch root are still found and renamed
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_run_renames_files_for_property_under_batch_root(tmp_path: Path) -> None:
|
||||
# Arrange
|
||||
csv_path = _write_csv(tmp_path, [("100", "1 High St", "AB1 2CD")])
|
||||
batch_assessment = _assessment_path(
|
||||
f"{BASE_PATH}/_Sero Batch 2", "1 High St", "AB1 2CD"
|
||||
)
|
||||
|
||||
sp = MagicMock()
|
||||
|
||||
def fake_get(path: str) -> dict[str, Any]:
|
||||
if path == BASE_PATH:
|
||||
return {"value": [_make_folder("_Sero Batch 2")]}
|
||||
if path == batch_assessment:
|
||||
return {"value": [_make_file("Survey.pdf", "id-1")]}
|
||||
raise ValueError("not found")
|
||||
|
||||
sp.get_folders_in_path.side_effect = fake_get
|
||||
|
||||
# Act
|
||||
SharepointRenamerOrchestrator(sp, csv_path).run()
|
||||
|
||||
# Assert
|
||||
sp.rename_file.assert_called_once_with("id-1", "100_1 High St AB1 2CD_Survey.pdf")
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# _process_folder — files only at root level
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue