系列: CICD
python
28 行
· 更新于 2026-02-03
test_api.py
CICD/sample_python_app/tests/test_api.py
"""Tests for the sample FastAPI application."""
from fastapi.testclient import TestClient
from app.api import app
client = TestClient(app)
def test_health_endpoint_returns_ok() -> None:
response = client.get("/healthz")
assert response.status_code == 200
payload = response.json()
assert payload["status"] == "ok"
assert payload["service"] == "Sample Python CI/CD API"
def test_greet_returns_message() -> None:
response = client.post("/greet", json={"name": "Ada"})
assert response.status_code == 200
payload = response.json()
assert payload["message"].startswith("Hello, Ada")
def test_greet_validates_name() -> None:
response = client.post("/greet", json={"name": ""})
assert response.status_code == 422
相关文章
CICD
python
更新于 2026-02-03
api.py
api.py — python source code from the CICD learning materials (CICD/sample_python_app/app/api.py).
阅读文章 →
CICD
python
更新于 2026-02-03
smoke_test.py
smoke_test.py — python source code from the CICD learning materials (CICD/sample_python_app/scripts/smoke_test.py).
阅读文章 →