fix(orion): correct report numbering toc and first page

This commit is contained in:
Schubert Ferenc 2026-07-11 12:48:01 +02:00
parent 503b343070
commit 47f54d3461
7 changed files with 283 additions and 137 deletions

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import re
from datetime import date
from pathlib import Path
@ -16,7 +17,7 @@ from app.services.validation_workflow import ValidationWorkflowService
from app.schemas.domain import ValidationCreate
from app.modules.orion.service import OrionReportService
from app.modules.orion.assets import SCHUBAMED_LOGO_PATH, schubamed_logo_uri
from app.modules.orion.template_service import ReportTemplateService
from app.modules.orion.template_service import REPORT_SECTIONS, ReportTemplateService
from app.modules.helios.service import HeliosImportService
@ -224,9 +225,9 @@ def test_orion_renders_reference_main_chapters(tmp_path):
html = OrionReportService(db, tmp_path).render_html(validation.id)
assert "1 Funktionsqualifikation" in html
assert "2.2 Prüfmittel" in html
assert "2.2 Prüfmittel zur thermoelektrischen Untersuchung" in html
assert "4 Ergebnisse der Validierung" in html
assert "9. Werkskalibrierzertifikate Sensoren" in html
assert "9 Werkskalibrierzertifikate Sensoren" in html
def test_orion_renders_uploaded_images_as_real_images(tmp_path):
@ -339,15 +340,89 @@ def test_orion_contains_required_reference_sections_and_three_runs(tmp_path):
"Zusammenfassendes Ergebnis der Validierung",
"1.1 Anlass und Ziel der Prüfung",
"1.2 Gesetzliche Grundlagen",
"3.2 Standardbeladung Testlauf 1",
"3.3 Standardbeladung Testlauf 2",
"3.4 Standardbeladung Testlauf 3",
"3.2 Standardbeladung (1. Durchlauf)",
"3.3 Standardbeladung (2. Durchlauf)",
"3.4 Standardbeladung (3. Durchlauf)",
]:
assert title in html
assert "Neutraler Logo-Platzhalter" not in html
assert "report-header-brand" in html
def test_orion_toc_uses_central_section_numbers_and_titles(tmp_path):
db = session()
customer, location, device = seed(db)
validation = valid_validation(customer, location, device)
db.add(validation)
db.flush()
html = OrionReportService(db, tmp_path).render_html(validation.id)
expected = [
"1.3 Angaben zum Gerät",
"1.8 Umgebungsbedingungen",
"2.3 Prüfkonfiguration",
"3.1.1 Vakuumtest",
"4.2 Empfehlungen und Auflagen",
"9 Werkskalibrierzertifikate Sensoren",
]
for label in expected:
assert label in html
assert "3.1.1 Leistungsqualifikation" not in html
assert "4.2 Trocknung" not in html
assert html.index("1 Funktionsqualifikation") < html.index("9 Werkskalibrierzertifikate")
def test_orion_html_has_single_cover_before_report_content(tmp_path):
db = session()
customer, location, device = seed(db)
validation = valid_validation(customer, location, device)
db.add(validation)
db.flush()
html = OrionReportService(db, tmp_path).render_html(validation.id)
assert html.count('class="cover-page"') == 1
assert html.index('class="cover-page"') < html.index('class="report-content"')
assert html.index('class="cover-page"') < html.index('class="report-meta"')
assert "<h1>PRÜFBERICHT ZUR VALIDIERUNG</h1>" in html
def test_orion_pdf_first_page_is_cover_not_blank(tmp_path):
from pypdf import PdfReader
db = session()
customer, location, device = seed(db)
validation = valid_validation(customer, location, device)
db.add(validation)
db.flush()
pdf_path = OrionReportService(db, tmp_path).render_pdf(validation.id)
first_page_text = PdfReader(str(pdf_path)).pages[0].extract_text() or ""
normalized_text = re.sub(r"\s+", "", first_page_text.upper())
assert "PRÜFBERICHTZURVALIDIERUNG" in normalized_text
assert "FUNKTIONS-UNDLEISTUNGSQUALIFIKATION" in normalized_text
def test_orion_bookmark_labels_are_created_from_central_sections(tmp_path):
db = session()
customer, location, device = seed(db)
validation = valid_validation(customer, location, device)
db.add(validation)
db.flush()
html = OrionReportService(db, tmp_path).render_html(validation.id)
bookmark_count = html.count("data-bookmark-label=")
toc_count = len([item for item in REPORT_SECTIONS if item.get("toc")])
assert bookmark_count == toc_count
for item in REPORT_SECTIONS:
number = item.get("number")
label = f"{number} {item['title']}" if number else item["title"]
assert f'data-bookmark-label="{label}"' in html
def test_orion_appends_pdf_attachments(tmp_path):
from pypdf import PdfReader, PdfWriter