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 == []