Initial commit: SMS Forwarder project with Docker support
This commit is contained in:
57
tests/test_main.py
Normal file
57
tests/test_main.py
Normal file
@ -0,0 +1,57 @@
|
||||
"""主应用测试."""
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from sms_forwarder.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_root():
|
||||
"""测试根路径."""
|
||||
response = client.get("/")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "message" in data
|
||||
assert "version" in data
|
||||
|
||||
|
||||
def test_health_check():
|
||||
"""测试健康检查."""
|
||||
response = client.get("/health")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "healthy"
|
||||
assert "timestamp" in data
|
||||
|
||||
|
||||
def test_status():
|
||||
"""测试状态接口."""
|
||||
response = client.get("/status")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "version" in data
|
||||
assert "uptime" in data
|
||||
assert "notifications_sent" in data
|
||||
assert "notifications_failed" in data
|
||||
|
||||
|
||||
def test_notify_without_auth():
|
||||
"""测试未认证的通知请求."""
|
||||
response = client.post("/notify", json={
|
||||
"api_key": "invalid-key",
|
||||
"message": {
|
||||
"sender": "test",
|
||||
"content": "test message"
|
||||
}
|
||||
})
|
||||
assert response.status_code == 401
|
||||
|
||||
|
||||
def test_notify_invalid_data():
|
||||
"""测试无效数据的通知请求."""
|
||||
response = client.post("/notify", json={
|
||||
"invalid": "data"
|
||||
})
|
||||
assert response.status_code == 422
|
Reference in New Issue
Block a user