后端开发完成

This commit is contained in:
Your Name
2026-01-26 18:21:34 +08:00
parent 40d2f3f6ac
commit b3876bba89
64 changed files with 1736 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
def test_login_success(client):
"""测试登录成功"""
response = client.post(
"/api/auth/login",
data={"username": "test_admin", "password": "test_password"}
)
assert response.status_code == 200
assert "access_token" in response.json()
assert response.json()["token_type"] == "bearer"
def test_login_invalid_username(client):
"""测试登录失败 - 用户名无效"""
response = client.post(
"/api/auth/login",
data={"username": "invalid_user", "password": "test_password"}
)
assert response.status_code == 401
assert "Incorrect username or password" in response.json()["detail"]
def test_login_invalid_password(client):
"""测试登录失败 - 密码无效"""
response = client.post(
"/api/auth/login",
data={"username": "test_admin", "password": "invalid_password"}
)
assert response.status_code == 401
assert "Incorrect username or password" in response.json()["detail"]
def test_login_empty_username(client):
"""测试登录失败 - 用户名为空"""
response = client.post(
"/api/auth/login",
data={"username": "", "password": "test_password"}
)
assert response.status_code == 422
def test_login_empty_password(client):
"""测试登录失败 - 密码为空"""
response = client.post(
"/api/auth/login",
data={"username": "test_admin", "password": ""}
)
assert response.status_code == 422