WebhockTransfer/tests/test_preview_endpoint.py

24 lines
745 B
Python

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