Spaces:
Sleeping
Sleeping
| """Multi-section report status finalization.""" | |
| from __future__ import annotations | |
| from unittest.mock import MagicMock | |
| import pytest | |
| from app.db.models import ReportStatus | |
| from app.services.generation import ( | |
| _finalize_multi_section_report, | |
| validate_section_codes, | |
| ) | |
| def test_finalize_all_failed() -> None: | |
| report = MagicMock() | |
| report.error_message = None | |
| _finalize_multi_section_report( | |
| report, failure_count=3, total=3, phase="generate" | |
| ) | |
| assert report.status == ReportStatus.failed | |
| def test_finalize_partial() -> None: | |
| report = MagicMock() | |
| report.error_message = None | |
| _finalize_multi_section_report( | |
| report, failure_count=1, total=4, phase="proofread" | |
| ) | |
| assert report.status == ReportStatus.partial | |
| assert "1 of 4" in (report.error_message or "") | |
| def test_validate_section_codes_rejects_unknown() -> None: | |
| with pytest.raises(ValueError, match="Unknown section"): | |
| validate_section_codes(["D", "NOT_A_REAL_SECTION"]) | |
| def test_finalize_complete() -> None: | |
| report = MagicMock() | |
| report.error_message = "old" | |
| _finalize_multi_section_report( | |
| report, failure_count=0, total=2, phase="enhance" | |
| ) | |
| assert report.status == ReportStatus.complete | |
| assert report.error_message is None | |