From f8d2bb8049e63c161fc0202292d2b50cb4e6068f Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Mon, 1 Jun 2026 15:52:44 +0000 Subject: [PATCH] =?UTF-8?q?Service=20deletes=20other-file=20temp=20paths?= =?UTF-8?q?=20after=20run=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/test_pashub_service.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/backend/pashub_fetcher/tests/test_pashub_service.py b/backend/pashub_fetcher/tests/test_pashub_service.py index 7ec8dea2..eec928f3 100644 --- a/backend/pashub_fetcher/tests/test_pashub_service.py +++ b/backend/pashub_fetcher/tests/test_pashub_service.py @@ -377,6 +377,31 @@ def test_run_persists_coordination_hub_file_source_when_pas_401_on_file_listing( assert added[0].file_source == FileSourceEnum.COORDINATION_HUB.value +# --------------------------------------------------------------------------- +# run(): get_other_files=True → other temp files deleted after run +# --------------------------------------------------------------------------- + + +def test_run_deletes_other_temp_files_when_get_other_files_true() -> None: + # Arrange + mock_client = MagicMock(spec=PashubClient) + mock_client.get_uprn_by_job_id.return_value = None + mock_client.get_evidence_files_by_job_id.return_value = make_downloaded( + core=["/tmp/core.pdf"], + other=["/tmp/other.pdf"], + ) + + service = make_service(pashub_client=mock_client) + + # Act + with patch("backend.pashub_fetcher.pashub_service.os.remove") as mock_remove: + service.run(make_request(get_other_files=True)) + + # Assert + mock_remove.assert_any_call("/tmp/core.pdf") + mock_remove.assert_any_call("/tmp/other.pdf") + + def test_run_warns_and_continues_when_site_notes_parsing_fails() -> None: mock_client = MagicMock(spec=PashubClient) mock_client.get_uprn_by_job_id.return_value = None