Preserve SharePoint distribution when the site-note save fails loudly 🟥

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-14 13:49:38 +00:00
parent 62c0151469
commit e31d2ad2d1

View file

@ -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"
)