feat: replace str.format with safe_render; add Pydantic validation to webhook route
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
|
||||
def test_preview_endpoint_success():
|
||||
client = TestClient(app)
|
||||
payload = {
|
||||
"template_content": "ok {trans_amt}",
|
||||
"sample_payload": {"trans_amt": 123}
|
||||
}
|
||||
resp = client.post("/admin/templates/preview", json=payload)
|
||||
assert resp.status_code == 200
|
||||
assert resp.json().get("rendered") == "ok 123"
|
||||
|
||||
|
||||
def test_preview_endpoint_strict_failure():
|
||||
client = TestClient(app)
|
||||
# Template refers to undefined variable -> StrictUndefined should cause error -> 400
|
||||
payload = {"template_content": "{{ undefined_var }}", "sample_payload": {}}
|
||||
resp = client.post("/admin/templates/preview", json=payload)
|
||||
assert resp.status_code == 400
|
||||
|
||||
Reference in New Issue
Block a user