RICS / backend /tests /test_docx_branded_template.py
StormShadow308's picture
Add demo documentation and Docker setup for v2 report generation system
aad7814
Raw
History Blame Contribute Delete
1.07 kB
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