File size: 1,297 Bytes
732b14f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""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