From e31d2ad2d13f6fb4c32fe26d11d5a5e569e4dc6b Mon Sep 17 00:00:00 2001 From: Daniel Roth Date: Tue, 14 Jul 2026 13:49:38 +0000 Subject: [PATCH] =?UTF-8?q?Preserve=20SharePoint=20distribution=20when=20t?= =?UTF-8?q?he=20site-note=20save=20fails=20loudly=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../tests/test_pashub_service.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) 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" + )