Initial commit: 浼佷笟寰俊 AI 鏈哄櫒浜哄姪鐞?MVP
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
26
backend/tests/test_auth.py
Normal file
26
backend/tests/test_auth.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""登录接口测试。"""
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test_login_fail_wrong_password():
|
||||
r = client.post("/api/auth/login", json={"username": "admin", "password": "wrong"})
|
||||
assert r.status_code == 401
|
||||
|
||||
|
||||
def test_login_fail_wrong_user():
|
||||
r = client.post("/api/auth/login", json={"username": "nobody", "password": "admin"})
|
||||
assert r.status_code == 401
|
||||
|
||||
|
||||
def test_login_returns_json():
|
||||
"""无 DB 时可能 401;有 DB 且 admin 存在时 200。仅断言响应为 JSON 且含 code。"""
|
||||
r = client.post("/api/auth/login", json={"username": "admin", "password": "admin"})
|
||||
assert r.headers.get("content-type", "").startswith("application/json")
|
||||
data = r.json()
|
||||
assert "code" in data
|
||||
assert "trace_id" in data
|
||||
Reference in New Issue
Block a user