46 lines
1.9 KiB
Python
46 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
|