Files
xiaoxia-saas/tests/integration/test_api.py
T
xiaoxia a5e5ba4426
Deploy / Build Production Runtime Images (push) Has been skipped
Deploy / Deploy Production (push) Has been skipped
Deploy / Production Browser E2E (push) Has been skipped
Deploy / Deploy Staging (push) Failing after 142h46m12s
CI/CD Pipeline / Frontend Lint (push) Failing after 142h46m42s
CI/CD Pipeline / Validate Code Quality And Tests (push) Failing after 142h46m50s
test: 添加核心流程 E2E 测试
- 认证流程(注册/登录/登出/获取用户信息,正向+反向共 10 个用例)
- 工作空间流程(创建/列出/详情/成员,共 6 个用例)
- 项目流程(创建/列出/详情/未授权,共 6 个用例)
- 素材库流程(创建库/列出库/创建素材/列出素材,共 8 个用例)

共 30 个回归测试用例,覆盖视频生成 SaaS 核心业务路径。
2026-07-03 14:07:29 +08:00

104 lines
2.7 KiB
Python
Executable File

"""
API 集成测试
"""
import pytest
from fastapi.testclient import TestClient
from apps.api.main import app
client = TestClient(app)
class TestAuthAPI:
"""认证 API 集成测试"""
def test_register_success(self):
"""测试注册成功"""
response = client.post(
"/api/v1/auth/register",
json={
"email": "test@example.com",
"password": "SecurePass123",
"username": "testuser",
"display_name": "Test User",
},
)
assert response.status_code == 201
data = response.json()
assert data["email"] == "test@example.com"
assert data["username"] == "testuser"
assert "user_id" in data
def test_register_duplicate_email(self):
"""测试重复邮箱注册"""
# 先注册一个用户
client.post(
"/api/v1/auth/register",
json={
"email": "duplicate@example.com",
"password": "SecurePass123",
"username": "user1",
"display_name": "User 1",
},
)
# 尝试用相同邮箱再次注册
response = client.post(
"/api/v1/auth/register",
json={
"email": "duplicate@example.com",
"password": "SecurePass123",
"username": "user2",
"display_name": "User 2",
},
)
assert response.status_code == 400
assert "already registered" in response.json()["detail"].lower()
def test_login_success(self):
"""测试登录成功"""
# 先注册
client.post(
"/api/v1/auth/register",
json={
"email": "login@example.com",
"password": "SecurePass123",
"username": "loginuser",
"display_name": "Login User",
},
)
# 登录
response = client.post(
"/api/v1/auth/login",
json={
"email": "login@example.com",
"password": "SecurePass123",
},
)
assert response.status_code == 200
data = response.json()
assert "access_token" in data
assert "refresh_token" in data
assert data["token_type"] == "bearer"
def test_login_wrong_password(self):
"""测试密码错误"""
response = client.post(
"/api/v1/auth/login",
json={
"email": "login@example.com",
"password": "WrongPassword123",
},
)
assert response.status_code == 401
if __name__ == "__main__":
pytest.main([__file__, "-v"])