diff --git a/tests/scripts/test_rename_sharepoint_files.py b/tests/scripts/test_rename_sharepoint_files.py index 92a33f7ad..b9d56562b 100644 --- a/tests/scripts/test_rename_sharepoint_files.py +++ b/tests/scripts/test_rename_sharepoint_files.py @@ -198,14 +198,46 @@ def test_ignores_package_items() -> None: # --------------------------------------------------------------------------- -def test_missing_folder_logs_warning_and_returns(caplog: pytest.LogCaptureFixture) -> None: +def test_missing_folder_returns_false_without_warning( + caplog: pytest.LogCaptureFixture, +) -> None: + # Arrange sp = MagicMock() sp.get_folders_in_path.side_effect = ValueError("not found") - _make_orchestrator(sp)._process_folder("missing/path", "400", "4 Elm St", "AA2 2BB") + # Act + found = _make_orchestrator(sp)._process_folder( + "missing/path", "400", "4 Elm St", "AA2 2BB" + ) + # Assert + assert found is False sp.rename_file.assert_not_called() - assert any("Missing folder" in r.message and "400" in r.message for r in caplog.records) + assert not any("Missing folder" in r.message for r in caplog.records) + + +def test_run_warns_once_when_property_missing_from_all_roots( + tmp_path: Path, caplog: pytest.LogCaptureFixture +) -> None: + # Arrange + csv_path = _write_csv(tmp_path, [("400", "4 Elm St", "AA2 2BB")]) + sp = MagicMock() + + def fake_get(path: str) -> dict[str, Any]: + if path == BASE_PATH: + return {"value": [_make_folder("_Sero Batch 2")]} + raise ValueError("not found") + + sp.get_folders_in_path.side_effect = fake_get + + # Act + SharepointRenamerOrchestrator(sp, csv_path).run() + + # Assert + sp.rename_file.assert_not_called() + warnings = [r for r in caplog.records if "Missing folder" in r.message] + assert len(warnings) == 1 + assert "400" in warnings[0].message # ---------------------------------------------------------------------------