40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
# API 集成测试 - UAT场景测试
|
|
import pytest
|
|
import sys
|
|
import os
|
|
|
|
# 添加当前目录到Python路径
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from api.base_api import BaseAPIClient
|
|
|
|
|
|
@pytest.fixture(scope='module')
|
|
def api_client():
|
|
"""API 客户端 fixture"""
|
|
client = BaseAPIClient(base_url='http://localhost:8084')
|
|
client.login('admin', 'admin123')
|
|
yield client
|
|
|
|
|
|
class TestUATScenario:
|
|
"""UAT 场景测试"""
|
|
|
|
def test_complete_user_workflow(self, api_client: BaseAPIClient):
|
|
"""测试完整用户工作流"""
|
|
# 1. 创建用户
|
|
response = api_client.post(
|
|
'/api/users',
|
|
json={
|
|
'username': 'uat_test_user',
|
|
'email': 'uat@test.com',
|
|
'password': 'uat123',
|
|
'nickname': 'UAT测试用户'
|
|
}
|
|
)
|
|
assert response.status_code == 201, "创建用户应该成功"
|
|
|
|
# 2. 获取用户列表
|
|
response = api_client.get('/api/users')
|
|
assert response.status_code == 200, "获取用户列表应该成功"
|