From 4220ce4bf04fd65381bba884563b3fc402ebd476 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 14 Jul 2026 09:29:28 +0000 Subject: [PATCH] =?UTF-8?q?Record=20a=20failure=20when=20the=20selection?= =?UTF-8?q?=20yields=20no=20export=20rows=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) --- .../test_scenario_export_orchestrator.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tests/orchestration/test_scenario_export_orchestrator.py b/tests/orchestration/test_scenario_export_orchestrator.py index 17e933f81..86ce864ea 100644 --- a/tests/orchestration/test_scenario_export_orchestrator.py +++ b/tests/orchestration/test_scenario_export_orchestrator.py @@ -11,6 +11,7 @@ from moto import mock_aws from openpyxl import load_workbook from domain.scenario_export.scenario_sheet import ExportMeasure, PropertyScenarioData +from domain.tasks.subtasks import SubTaskFailure from infrastructure.s3.s3_client import S3Client from orchestration.scenario_export_orchestrator import ScenarioExportOrchestrator from tests.infrastructure import make_boto_client @@ -155,3 +156,29 @@ def test_an_email_failure_does_not_lose_the_built_export(exports: S3Client) -> N # on sub_task.outputs, so the link isn't lost). assert result.presigned_url assert exports.get_object(result.export_s3_key) + + +def test_a_selection_that_yields_no_rows_is_a_recorded_failure( + exports: S3Client, +) -> None: + # arrange — no property has a default Plan under the scenario (model A), so + # the repo returns no rows for it. + email = _RecordingEmail() + orchestrator = ScenarioExportOrchestrator( + rows=_FakeRows({}), + scenarios=_FakeScenarioNames({5: "Fabric first"}), + exports=exports, + email=email, + url_ttl_seconds=3600, + ) + + # act / assert — a recorded failure, never an empty workbook emailed. + with pytest.raises(SubTaskFailure): + orchestrator.run( + portfolio_id=100, + scenario_ids=[5], + property_ids=[1], + recipient_email="user@example.com", + export_name="portfolio-100", + ) + assert email.sent == []