2026-04-29 11:28:04 +02:00
|
|
|
"""Berichtsprofil-Schema: Defaults und Validierung."""
|
|
|
|
|
|
|
|
|
|
from report_profile_schema import (
|
|
|
|
|
ReportProfilePayload,
|
|
|
|
|
default_report_profile_dict,
|
|
|
|
|
parse_report_profile,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_default_profile_roundtrip():
|
|
|
|
|
d = default_report_profile_dict()
|
|
|
|
|
p = ReportProfilePayload.model_validate(d)
|
|
|
|
|
assert p.version == 1
|
|
|
|
|
assert len(p.blocks) >= 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_empty_uses_default():
|
|
|
|
|
p = parse_report_profile({})
|
|
|
|
|
assert len(p.blocks) >= 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_chart_block_unknown_id_raises():
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
raw = {
|
|
|
|
|
"version": 1,
|
|
|
|
|
"document_title": "",
|
|
|
|
|
"blocks": [{"type": "chart", "chart_id": "not_a_chart", "window_days": 28}],
|
|
|
|
|
}
|
|
|
|
|
with pytest.raises(Exception):
|
|
|
|
|
ReportProfilePayload.model_validate(raw)
|
2026-04-29 11:46:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_viz_bundle_roundtrip():
|
|
|
|
|
raw = {
|
|
|
|
|
"version": 1,
|
|
|
|
|
"document_title": "",
|
|
|
|
|
"blocks": [
|
|
|
|
|
{"type": "viz_bundle", "bundle_id": "body_history_viz", "config": {"chart_days": 14}},
|
|
|
|
|
],
|
|
|
|
|
}
|
|
|
|
|
p = ReportProfilePayload.model_validate(raw)
|
|
|
|
|
assert p.blocks[0].type == "viz_bundle"
|
|
|
|
|
assert p.blocks[0].config.get("chart_days") == 14
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_viz_bundle_unknown_raises():
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
raw = {
|
|
|
|
|
"version": 1,
|
|
|
|
|
"document_title": "",
|
|
|
|
|
"blocks": [{"type": "viz_bundle", "bundle_id": "not_a_bundle", "config": {}}],
|
|
|
|
|
}
|
|
|
|
|
with pytest.raises(Exception):
|
|
|
|
|
ReportProfilePayload.model_validate(raw)
|