feat: 重构测试框架并优化代码结构

refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests
style: 为Java类添加文档注释
docs: 更新.gitignore和配置文件
test: 添加性能测试和Playwright测试脚本
chore: 清理旧测试文件和配置
This commit is contained in:
张翔
2026-03-14 13:49:39 +08:00
parent 9e187f42e5
commit c50ccd258f
178 changed files with 8655 additions and 2519 deletions
+78
View File
@@ -0,0 +1,78 @@
"""
认证测试用例
"""
import pytest
from api.auth_api import AuthAPI
from config.settings import settings
@pytest.mark.auth
@pytest.mark.smoke
class TestAuth:
"""认证测试类"""
@pytest.mark.asyncio
async def test_login_success(self, http_client):
"""测试成功登录"""
auth_api = AuthAPI(http_client)
response = await auth_api.login(settings.TEST_USERNAME, settings.TEST_PASSWORD)
assert response.status_code == 200
data = response.json()
assert "token" in data
assert isinstance(data["token"], str)
assert "userId" in data
assert "username" in data
@pytest.mark.asyncio
async def test_login_invalid_credentials(self, http_client):
"""测试无效凭证登录"""
auth_api = AuthAPI(http_client)
response = await auth_api.login("invalid_user", "invalid_password")
assert response.status_code == 401
@pytest.mark.asyncio
async def test_login_missing_fields(self, http_client):
"""测试缺少必填字段"""
auth_api = AuthAPI(http_client)
response = await http_client.post("/api/auth/login", json={
"username": "test"
})
assert response.status_code == 400
@pytest.mark.asyncio
async def test_register_success(self, http_client):
"""测试注册成功"""
import time
timestamp = int(time.time() * 1000)
response = await http_client.post("/api/auth/register", json={
"username": f"testuser_{timestamp}",
"password": "password123",
"email": f"test_{timestamp}@example.com"
})
assert response.status_code == 201
data = response.json()
assert "id" in data
assert data["username"] == f"testuser_{timestamp}"
@pytest.mark.asyncio
async def test_register_duplicate_username(self, http_client):
"""测试注册重复用户名"""
response = await http_client.post("/api/auth/register", json={
"username": "admin",
"password": "password123",
"email": "admin@example.com"
})
assert response.status_code == 500
@pytest.mark.asyncio
async def test_logout_success(self, http_client):
"""测试登出成功"""
response = await http_client.post("/api/auth/logout")
assert response.status_code == 200