-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathtest_main.py
More file actions
54 lines (41 loc) · 1.5 KB
/
Copy pathtest_main.py
File metadata and controls
54 lines (41 loc) · 1.5 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
49
50
51
52
53
54
"""Tests for the main FastAPI application."""
from fastapi.testclient import TestClient
from app.main import app
client = TestClient(app)
def test_root():
"""Test the root endpoint."""
response = client.get("/")
assert response.status_code == 200
assert response.json() == {"message": "Welcome to FastAPI GitOps Starter!"}
def test_health_check():
"""Test the health check endpoint."""
response = client.get("/health")
assert response.status_code == 200
data = response.json()
assert data["status"] == "healthy"
assert data["service"] == "fastapi-gitops-starter"
def test_list_items():
"""Test the list items endpoint."""
response = client.get("/api/items")
assert response.status_code == 200
data = response.json()
assert "items" in data
assert len(data["items"]) == 3
assert data["items"][0]["id"] == 1
def test_get_item():
"""Test the get item endpoint."""
response = client.get("/api/items/5")
assert response.status_code == 200
data = response.json()
assert data["id"] == 5
assert data["name"] == "Item 5"
assert "item number 5" in data["description"]
def test_create_item():
"""Test the create item endpoint."""
response = client.post("/api/items?name=Test Item&description=Test Description")
assert response.status_code == 200
data = response.json()
assert data["id"] == 999
assert data["name"] == "Test Item"
assert data["description"] == "Test Description"
assert data["created"] is True