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