diff --git a/backend/pashub_fetcher/tests/test_pashub_service.py b/backend/pashub_fetcher/tests/test_pashub_service.py index aa8b6e2ce..1acb583d3 100644 --- a/backend/pashub_fetcher/tests/test_pashub_service.py +++ b/backend/pashub_fetcher/tests/test_pashub_service.py @@ -896,3 +896,34 @@ def test_run_fetches_summary_from_coordination_client_on_primary_auth_failure() coord_client.get_rdsap_summary_by_job_id.assert_called_once() saved: EpcPropertyData = mock_save.call_args[0][1] assert saved.energy_rating_current == 78 + + +def test_run_uploads_to_sharepoint_even_when_summary_fetch_fails() -> None: + # Arrange — file distribution must survive a loud site-note save failure + mock_client = _site_note_client() + mock_client.get_rdsap_summary_by_job_id.side_effect = RuntimeError("summary down") + + mock_sharepoint = MagicMock(spec=DomnaSharepointClient) + mock_sharepoint.get_folders_in_path.return_value = { + "value": [{"name": "123 Main St"}] + } + service = make_service(pashub_client=mock_client, sharepoint_client=mock_sharepoint) + + # Act / Assert + with ( + patch("backend.pashub_fetcher.pashub_service.upload_file_to_s3"), + patch("backend.pashub_fetcher.pashub_service.db_session"), + patch("backend.pashub_fetcher.pashub_service.os.remove"), + ): + with pytest.raises(RuntimeError): + service.run( + make_request( + uprn="12345", + sharepoint_link="Retrofit/Properties", + address="123 Main St | deal", + ) + ) + + mock_sharepoint.upload_file.assert_any_call( + RD_SAP_SITE_NOTE_PATH, "Retrofit/Properties/123 Main St", "RdSAP_SiteNote_001.pdf" + )