-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_routes.py
More file actions
48 lines (34 loc) · 1.48 KB
/
test_routes.py
File metadata and controls
48 lines (34 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Unit and integration tests for NX AI routes."""
from unittest.mock import MagicMock
from fastapi.testclient import TestClient
from app.api.routes import get_db_connection
from app.main import app
client = TestClient(app)
def test_root_returns_welcome_message() -> None:
"""GET / should return a welcome message."""
response = client.get("/")
assert response.status_code == 200
json_data = response.json()
assert "meta" in json_data
assert "data" in json_data
assert "message" in json_data["meta"]
assert "NX AI" in json_data["meta"]["message"]
def test_health_returns_ok() -> None:
"""GET /health should return status ok."""
response = client.get("/health")
assert response.status_code == 200
assert response.json() == {"status": "ok"}
def test_echo_returns_message() -> None:
"""POST /echo should return the provided message."""
response = client.post("/echo", json={"message": "hello"})
assert response.status_code == 200
assert response.json() == {"echo": "hello"}
def test_echo_empty_string() -> None:
"""POST /echo with an empty string should echo back an empty string."""
response = client.post("/echo", json={"message": ""})
assert response.status_code == 200
assert response.json() == {"echo": ""}
def test_echo_missing_body_returns_422() -> None:
"""POST /echo without a body should return 422 Unprocessable Entity."""
response = client.post("/echo", json={})
assert response.status_code == 422