Files
task_flow/tests/test_health.py

46 lines
1008 B
Python

from datetime import datetime
import pytest
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_health_ok():
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "ok"
assert "server_time" in data
# Validate ISO-8601 format (basic check via fromisoformat)
parsed = datetime.fromisoformat(data["server_time"])
assert isinstance(parsed, datetime)
def test_health_idempotent_time_increases():
response1 = client.get("/health")
response2 = client.get("/health")
assert response1.status_code == 200
assert response2.status_code == 200
data1 = response1.json()
data2 = response2.json()
t1 = datetime.fromisoformat(data1["server_time"])
t2 = datetime.fromisoformat(data2["server_time"])
assert t2 >= t1
def test_health_method_not_allowed():
response = client.post("/health")
assert response.status_code == 405