From ce749061aae0098bc9ab52253c18e7eaeeb7c040 Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Fri, 3 Jul 2026 11:18:10 +0000 Subject: [PATCH] =?UTF-8?q?Renamer=20warns=20once=20per=20property=20only?= =?UTF-8?q?=20after=20all=20roots=20miss=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- tests/scripts/test_rename_sharepoint_files.py | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) 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 # ---------------------------------------------------------------------------