feat: add safe_render using Jinja2; add tests

This commit is contained in:
auto-bot
2025-12-24 10:50:34 +08:00
parent a5678de78b
commit ec58508476
2 changed files with 62 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import pytest
from app.templates import safe_render
def test_safe_render_legacy_and_nested():
tpl = "收到{actual_ref_amt}元 by {trans_order_info.remark}"
ctx = {"actual_ref_amt": 88.88, "trans_order_info": {"remark": "order123"}}
out = safe_render(tpl, ctx)
assert "88.88" in out
assert "order123" in out
def test_safe_render_missing_var_raises():
tpl = "Hello {missing_var}"
with pytest.raises(Exception):
safe_render(tpl, {})