Files
contact.allucanget.biz/tests/test_contact_api.py
zwitschi 4cefd4e3ab
Some checks failed
CI / test (3.11) (push) Failing after 5m36s
CI / build-image (push) Has been skipped
v1
2025-10-22 16:48:55 +02:00

40 lines
984 B
Python

import importlib
import pytest
server_app_module = importlib.import_module("server.app")
# Expose app and init_db from the imported module
app = server_app_module.app
init_db = server_app_module.init_db
@pytest.fixture
def client():
with app.test_client() as client:
yield client
def post(client, data):
return client.post("/api/contact", data=data)
def test_valid_submission_creates_record_and_returns_201(client):
resp = post(
client,
{"name": "Test User", "email": "test@example.com",
"message": "Hello", "consent": "on"},
)
assert resp.status_code in (201, 202)
body = resp.get_json()
assert body["status"] == "ok"
assert isinstance(body.get("id"), int)
def test_missing_required_fields_returns_400(client):
resp = post(client, {"name": "", "email": "", "message": ""})
assert resp.status_code == 400
body = resp.get_json()
assert body["status"] == "error"
assert "errors" in body