mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-08-03 05:18:22 +00:00
Complete a rename run that hit locked files or missing folders, and reject an unusable site 🟩
Green on arrival: both fall out of the summary the run now returns and of the guarded site lookup. Pinned after verifying they bite — an unguarded DomnaSites[name] completes an "ECO" run that renames files under a different site's alias. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
0836b18d5b
commit
be1d6faea0
1 changed files with 93 additions and 0 deletions
|
|
@ -260,3 +260,96 @@ def test_dry_run_in_an_sqs_record_body_renames_nothing(
|
|||
"failed": [],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Partial failures complete, they do not fail the run
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_run_completes_with_rejected_files_and_missing_folders_listed(
|
||||
harness: Harness, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""One locked file, or a property with no folder, must not turn a
|
||||
productive run red — the failures are the record (ADR-0060)."""
|
||||
# Arrange
|
||||
sharepoint = FakeSharepoint(
|
||||
_one_property_site(
|
||||
_file("Locked.pdf", "id-1"), _file("Survey.pdf", "id-2")
|
||||
),
|
||||
reject={"id-1": PermissionError("locked by another user")},
|
||||
)
|
||||
_install(
|
||||
monkeypatch,
|
||||
tmp_path,
|
||||
sharepoint,
|
||||
rows=[(UPRN, ADDRESS, POSTCODE), ("999", "9 Nowhere Rd", "ZZ9 9ZZ")],
|
||||
)
|
||||
|
||||
# Act
|
||||
result = _handler(harness)(_sqs_event({"sharepoint_site": SITE}), None)
|
||||
|
||||
# Assert
|
||||
assert harness.tasks.get(_task_id(result)).status is TaskStatus.COMPLETE
|
||||
subtask = harness.subtasks.get(_subtask_id(result))
|
||||
assert subtask.status is SubTaskStatus.COMPLETE
|
||||
assert subtask.outputs == {
|
||||
"result": {
|
||||
"renamed": 1,
|
||||
"would_rename": 0,
|
||||
"skipped_already_canonical": 0,
|
||||
"skipped_images": 0,
|
||||
"missing_folders": ["999"],
|
||||
"failed": [
|
||||
{
|
||||
"uprn": UPRN,
|
||||
"original_name": "Locked.pdf",
|
||||
"new_name": f"{UPRN}_{ADDRESS} {POSTCODE}_Locked.pdf",
|
||||
"error": "locked by another user",
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# An unusable site is rejected before anything is touched
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_unconfigured_site_fails_the_run_without_touching_sharepoint(
|
||||
harness: Harness, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
"""Sites take their id from the environment at import, so every site this
|
||||
Lambda does not configure collapses into an alias of the first one. An
|
||||
unguarded lookup would return a valid member for the *wrong* site."""
|
||||
# Arrange
|
||||
sharepoint = FakeSharepoint(_one_property_site(_file("Survey.pdf", "id-1")))
|
||||
_install(monkeypatch, tmp_path, sharepoint)
|
||||
monkeypatch.delenv("ECO_SHAREPOINT_ID", raising=False)
|
||||
|
||||
# Act
|
||||
result = _handler(harness)(_sqs_event({"sharepoint_site": "ECO"}), None)
|
||||
|
||||
# Assert
|
||||
subtask = harness.subtasks.get(_subtask_id(result))
|
||||
assert subtask.status is SubTaskStatus.FAILED
|
||||
assert "ECO_SHAREPOINT_ID is unset" in (subtask.outputs or {})["error"]
|
||||
assert sharepoint.renamed == []
|
||||
|
||||
|
||||
def test_unrecognised_site_fails_the_run(
|
||||
harness: Harness, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
# Arrange
|
||||
sharepoint = FakeSharepoint(_one_property_site(_file("Survey.pdf", "id-1")))
|
||||
_install(monkeypatch, tmp_path, sharepoint)
|
||||
|
||||
# Act
|
||||
result = _handler(harness)(_sqs_event({"sharepoint_site": "NOT_A_SITE"}), None)
|
||||
|
||||
# Assert
|
||||
subtask = harness.subtasks.get(_subtask_id(result))
|
||||
assert subtask.status is SubTaskStatus.FAILED
|
||||
assert "Unrecognised SharePoint site 'NOT_A_SITE'" in (subtask.outputs or {})["error"]
|
||||
assert sharepoint.renamed == []
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue