feat: 重构测试框架并优化代码结构
refactor(tests): 将e2e_tests迁移到tests_suite和api_integration_tests style: 为Java类添加文档注释 docs: 更新.gitignore和配置文件 test: 添加性能测试和Playwright测试脚本 chore: 清理旧测试文件和配置
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user