mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
correct import in test file
This commit is contained in:
parent
a6050fc1c7
commit
b9cbea367d
1 changed files with 22 additions and 37 deletions
|
|
@ -1,10 +1,12 @@
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import MagicMock, call, patch
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import scripts.rename_sharepoint_files as module
|
from orchestration.sharepoint_renamer_orchestrator import (
|
||||||
from scripts.rename_sharepoint_files import build_canonical_filename, process_folder
|
SharepointRenamerOrchestrator,
|
||||||
|
build_canonical_filename,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _make_file(name: str, item_id: str = "id-1") -> dict[str, Any]:
|
def _make_file(name: str, item_id: str = "id-1") -> dict[str, Any]:
|
||||||
|
|
@ -19,6 +21,12 @@ def _make_package(name: str) -> dict[str, Any]:
|
||||||
return {"name": name, "package": {}}
|
return {"name": name, "package": {}}
|
||||||
|
|
||||||
|
|
||||||
|
def _make_orchestrator(sp: MagicMock) -> SharepointRenamerOrchestrator:
|
||||||
|
orchestrator = SharepointRenamerOrchestrator.__new__(SharepointRenamerOrchestrator)
|
||||||
|
orchestrator._sp_client = sp
|
||||||
|
return orchestrator
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# build_canonical_filename
|
# build_canonical_filename
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
@ -39,7 +47,7 @@ def test_no_prefix_still_canonical() -> None:
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# process_folder — files only at root level
|
# _process_folder — files only at root level
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -52,8 +60,7 @@ def test_renames_top_level_files(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch.object(module, "DRY_RUN", False):
|
_make_orchestrator(sp)._process_folder("some/path", "100", "1 High St", "AB1 2CD")
|
||||||
process_folder(sp, "some/path", "100", "1 High St", "AB1 2CD")
|
|
||||||
|
|
||||||
assert sp.rename_file.call_count == 2
|
assert sp.rename_file.call_count == 2
|
||||||
sp.rename_file.assert_any_call("id-1", "100_1 High St AB1 2CD_Survey.pdf")
|
sp.rename_file.assert_any_call("id-1", "100_1 High St AB1 2CD_Survey.pdf")
|
||||||
|
|
@ -61,7 +68,7 @@ def test_renames_top_level_files(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# process_folder — recursive two-level hierarchy
|
# _process_folder — recursive two-level hierarchy
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -84,8 +91,7 @@ def test_recurses_into_subfolders_and_renames_all_files() -> None:
|
||||||
root_contents if path == "base/path" else suba_contents
|
root_contents if path == "base/path" else suba_contents
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch.object(module, "DRY_RUN", False):
|
_make_orchestrator(sp)._process_folder("base/path", "200", "2 Main Rd", "XY9 8ZW")
|
||||||
process_folder(sp, "base/path", "200", "2 Main Rd", "XY9 8ZW")
|
|
||||||
|
|
||||||
assert sp.rename_file.call_count == 2
|
assert sp.rename_file.call_count == 2
|
||||||
sp.rename_file.assert_any_call("root-file", "200_2 Main Rd XY9 8ZW_Root.pdf")
|
sp.rename_file.assert_any_call("root-file", "200_2 Main Rd XY9 8ZW_Root.pdf")
|
||||||
|
|
@ -95,25 +101,22 @@ def test_recurses_into_subfolders_and_renames_all_files() -> None:
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# process_folder — non-file, non-folder items are skipped
|
# _process_folder — non-file, non-folder items are skipped
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def test_ignores_package_items() -> None:
|
def test_ignores_package_items() -> None:
|
||||||
sp = MagicMock()
|
sp = MagicMock()
|
||||||
sp.get_folders_in_path.return_value = {
|
sp.get_folders_in_path.return_value = {"value": [_make_package("Notebook")]}
|
||||||
"value": [_make_package("Notebook")]
|
|
||||||
}
|
|
||||||
|
|
||||||
with patch.object(module, "DRY_RUN", False):
|
_make_orchestrator(sp)._process_folder("some/path", "300", "3 Oak Ave", "ZZ1 1ZZ")
|
||||||
process_folder(sp, "some/path", "300", "3 Oak Ave", "ZZ1 1ZZ")
|
|
||||||
|
|
||||||
sp.rename_file.assert_not_called()
|
sp.rename_file.assert_not_called()
|
||||||
assert sp.get_folders_in_path.call_count == 1
|
assert sp.get_folders_in_path.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# process_folder — missing folder
|
# _process_folder — missing folder
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -121,31 +124,14 @@ def test_missing_folder_logs_warning_and_returns(caplog: pytest.LogCaptureFixtur
|
||||||
sp = MagicMock()
|
sp = MagicMock()
|
||||||
sp.get_folders_in_path.side_effect = ValueError("not found")
|
sp.get_folders_in_path.side_effect = ValueError("not found")
|
||||||
|
|
||||||
with patch.object(module, "DRY_RUN", False):
|
_make_orchestrator(sp)._process_folder("missing/path", "400", "4 Elm St", "AA2 2BB")
|
||||||
process_folder(sp, "missing/path", "400", "4 Elm St", "AA2 2BB")
|
|
||||||
|
|
||||||
sp.rename_file.assert_not_called()
|
sp.rename_file.assert_not_called()
|
||||||
assert any("Missing folder" in r.message and "400" in r.message for r in caplog.records)
|
assert any("Missing folder" in r.message and "400" in r.message for r in caplog.records)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# process_folder — dry run
|
# _process_folder — already-canonical files are skipped
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
def test_dry_run_logs_without_renaming(caplog: pytest.LogCaptureFixture) -> None:
|
|
||||||
sp = MagicMock()
|
|
||||||
sp.get_folders_in_path.return_value = {"value": [_make_file("Doc.pdf", "id-x")]}
|
|
||||||
|
|
||||||
with patch.object(module, "DRY_RUN", True):
|
|
||||||
process_folder(sp, "some/path", "500", "5 Pine Ln", "BB3 3CC")
|
|
||||||
|
|
||||||
sp.rename_file.assert_not_called()
|
|
||||||
assert any("[DRY RUN]" in r.message for r in caplog.records)
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
|
||||||
# process_folder — already-canonical files are skipped
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -155,7 +141,6 @@ def test_skips_already_canonical_files() -> None:
|
||||||
"value": [_make_file("500_Pine Ln BB3 3CC_Doc.pdf", "id-y")]
|
"value": [_make_file("500_Pine Ln BB3 3CC_Doc.pdf", "id-y")]
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch.object(module, "DRY_RUN", False):
|
_make_orchestrator(sp)._process_folder("some/path", "500", "5 Pine Ln", "BB3 3CC")
|
||||||
process_folder(sp, "some/path", "500", "5 Pine Ln", "BB3 3CC")
|
|
||||||
|
|
||||||
sp.rename_file.assert_not_called()
|
sp.rename_file.assert_not_called()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue