Record a failure when the selection yields no export rows 🟥

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-07-14 09:29:28 +00:00
parent 5ee8b2df50
commit 4220ce4bf0

View file

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