Spaces:
Runtime error
Runtime error
File size: 1,069 Bytes
aad7814 | 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 | from __future__ import annotations
import io
import zipfile
from pathlib import Path
from docx import Document
from backend.utils import docx_builder
from backend.models.report import GeneratedSection, ReportResult
from backend.models.schema import SectionDefinition, TemplateSchema
def test_branded_template_used_when_configured(tmp_path, monkeypatch):
branded = tmp_path / "firm.docx"
doc = Document()
doc.add_paragraph("Firm letterhead")
doc.save(str(branded))
schema = TemplateSchema(
sections=[SectionDefinition(id="A", title="About", order=0)],
)
result = ReportResult(
tenant_id="t",
schema_version=1,
sections=[
GeneratedSection(section_id="A", title="About", text="Inspection noted.", status="OK"),
],
)
data = docx_builder.build_docx(result, schema, template_docx_path=str(branded))
with zipfile.ZipFile(io.BytesIO(data)) as zf:
xml = zf.read("word/document.xml").decode("utf-8")
assert "Firm letterhead" in xml
assert "Inspection noted" in xml
|