Files
descarga_factura_transporte/tests/test_notificaciones.py
T
GeorgeandClaude Sonnet 5.5 1d6d869111 se reorganiza tests/ y se agrega suite pytest
Los scripts manuales pasan a tools/ y los correos de ejemplo a
tests/fixtures/. Suite de 95 pruebas: caracterización de la extracción sobre
los 46 correos (resultados esperados en tests/golden/, fuera de la carpeta
que descargar_correos_prueba borra), unitarias de draft_sap, notificaciones,
documentos, adjuntos y config_validator, y flujo completo de
_procesar_un_correo con SAP/HANA/Outlook simulados. pytest como dependencia
dev y configuración en pyproject.toml.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-20 22:03:38 -05:00

47 lines
1.9 KiB
Python

import notificaciones as n
FACTURA = {"serie": "F002", "numero": "486", "razon_social_emisor": "TRANSPORTES SA"}
def test_cuerpo_draft_creado():
html = n.build_notification_body("created", FACTURA, "<t1/>", "<t2/>", doc_entry=2021)
assert "✅" in html and "<b>DocEntry:</b> 2021" in html
assert "F002-486" in html and "TRANSPORTES SA" in html
assert "<t1/>" in html and "<t2/>" in html
def test_cuerpo_error():
html = n.build_notification_body("error", FACTURA, "<t1/>", "<t2/>", error=ValueError("boom"))
assert "❌ Error al crear Draft" in html and "boom" in html
def test_cuerpo_precios_no_coinciden():
html = n.build_notification_body("skipped", FACTURA, "<t1/>", "<t2/>")
assert "Draft NO creado" in html and "no coinciden" in html
def test_tabla_de_validacion():
resultados = [
{"grflete": "09T001-1", "ok": True, "draft_price": 100.0, "sap_price": 100.0,
"warehouse_code": "A-X", "label": "LineTotal"},
{"grflete": "-", "ok": False, "draft_price": None, "sap_price": None,
"warehouse_code": "-", "label": "Sin guía de referencia"},
]
html = n.build_validation_html(resultados)
assert "09T001-1" in html and "100.000000" in html
assert html.count("✅") == 1 and html.count("❌") == 1
assert "Sin guía de referencia" in html
def test_valor_referencial_coincide():
factura = {"lineas": [{"valor_referencial": 10.0}, {"valor_referencial": 5.0}]}
guias = [{"serie": "T001", "numero": "1", "valor_sap": 9.0}, {"serie": "T001", "numero": "2", "valor_sap": 6.0}]
html = n.build_valor_referencial_html(factura, guias)
assert "✅ Coincide" in html and "<b>15.00</b>" in html
def test_valor_referencial_no_coincide():
factura = {"lineas": [{"valor_referencial": 10.0}]}
html = n.build_valor_referencial_html(factura, [{"serie": "T001", "numero": "1", "valor_sap": 9.0}])
assert "❌ No coincide" in html