Estado semilla del servicio: identidad, plantillas placeholder, FSM de sesión, extractor PDF/DOCX/MD, renderer python-docx, conversor LibreOffice headless, worker de cola Redis y persistencia Postgres. Listo para conectarse a Quetzalcóatl vía valeria:entrada / quetzalcoatl:envios. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
"""Tests del renderer: márgenes y tamaños correctos."""
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from valeria.extractor import Parrafo
|
|
from valeria.modelos import TamanoDocumento
|
|
from valeria.renderer import (
|
|
CONFIG_POR_TAMANO,
|
|
renderizar_impresion,
|
|
)
|
|
|
|
|
|
def test_config_carta():
|
|
config = CONFIG_POR_TAMANO[TamanoDocumento.CARTA]
|
|
assert config.margen_superior_cm == 5.0
|
|
assert config.margen_inferior_cm == 4.0
|
|
assert config.margen_izquierdo_cm == 2.0
|
|
assert config.margen_derecho_cm == 2.0
|
|
|
|
|
|
def test_config_oficio():
|
|
config = CONFIG_POR_TAMANO[TamanoDocumento.OFICIO]
|
|
assert config.margen_superior_cm == 6.5
|
|
assert config.margen_inferior_cm == 5.0
|
|
assert config.margen_izquierdo_cm == 2.0
|
|
assert config.margen_derecho_cm == 2.0
|
|
|
|
|
|
def test_oficio_es_mas_alto_que_carta():
|
|
carta = CONFIG_POR_TAMANO[TamanoDocumento.CARTA]
|
|
oficio = CONFIG_POR_TAMANO[TamanoDocumento.OFICIO]
|
|
assert oficio.alto_cm > carta.alto_cm
|
|
|
|
|
|
def test_renderizar_impresion_carta(tmp_path: Path):
|
|
"""Genera un DOCX de impresión y verifica los márgenes."""
|
|
parrafos = [
|
|
Parrafo(texto="Hola mundo."),
|
|
Parrafo(texto="Segundo párrafo."),
|
|
]
|
|
destino = tmp_path / "out.docx"
|
|
renderizar_impresion(parrafos, TamanoDocumento.CARTA, destino)
|
|
assert destino.exists()
|
|
|
|
# Abrir y verificar márgenes
|
|
from docx import Document
|
|
from docx.shared import Cm
|
|
doc = Document(str(destino))
|
|
section = doc.sections[0]
|
|
# Comparar con tolerancia: Cm() devuelve EMUs, comparamos en EMUs
|
|
assert section.top_margin == Cm(5.0)
|
|
assert section.bottom_margin == Cm(4.0)
|
|
assert section.left_margin == Cm(2.0)
|
|
assert section.right_margin == Cm(2.0)
|
|
|
|
|
|
def test_renderizar_impresion_oficio(tmp_path: Path):
|
|
parrafos = [Parrafo(texto="Contenido oficio.")]
|
|
destino = tmp_path / "out_oficio.docx"
|
|
renderizar_impresion(parrafos, TamanoDocumento.OFICIO, destino)
|
|
assert destino.exists()
|
|
|
|
from docx import Document
|
|
from docx.shared import Cm
|
|
doc = Document(str(destino))
|
|
section = doc.sections[0]
|
|
assert section.top_margin == Cm(6.5)
|
|
assert section.bottom_margin == Cm(5.0)
|
|
|
|
|
|
def test_renderizar_preserva_contenido(tmp_path: Path):
|
|
"""El texto del párrafo aparece literal en el DOCX generado."""
|
|
texto_unico = "Esta es una frase muy específica para probar literal."
|
|
parrafos = [Parrafo(texto=texto_unico)]
|
|
destino = tmp_path / "literal.docx"
|
|
renderizar_impresion(parrafos, TamanoDocumento.CARTA, destino)
|
|
|
|
from docx import Document
|
|
doc = Document(str(destino))
|
|
textos = [p.text for p in doc.paragraphs]
|
|
assert texto_unico in textos
|