-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathtest_main.py
More file actions
61 lines (48 loc) · 1.66 KB
/
Copy pathtest_main.py
File metadata and controls
61 lines (48 loc) · 1.66 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
55
56
57
58
59
60
61
"""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."""
# Send a POST request
response = client.post(
"/api/items",
params={"name": "Test Item", "description": "This is a test item"}
)
# Check request
assert response.status_code == 200
# Get the response data
data = response.json()
# Check expected fields are in the response
assert data["id"] == 999
assert data["name"] == "Test Item"
assert data["description"] == "This is a test item"
assert data["created"]