feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
This commit is contained in:
@@ -0,0 +1,204 @@
|
||||
# test-tools - API测试工具
|
||||
|
||||
## 概述
|
||||
|
||||
test-tools是一个基于Python的API测试工具模块,提供完整的API测试功能,包括认证、测试用例执行、报告生成等功能。
|
||||
|
||||
## 目录结构
|
||||
|
||||
```
|
||||
test-tools/
|
||||
├── config/ # 配置文件目录
|
||||
│ ├── test_config.yaml # 测试配置文件
|
||||
│ └── settings.py # 配置管理模块
|
||||
├── core/ # 核心功能模块
|
||||
├── data/ # 测试数据目录
|
||||
├── utils/ # 工具函数目录
|
||||
├── test_cases/ # 测试用例目录
|
||||
├── interfaces/ # 接口定义目录
|
||||
├── main.py # 主程序入口
|
||||
├── main_enhanced.py # 增强版主程序
|
||||
├── requirements.txt # Python依赖
|
||||
├── pyproject.toml # Poetry配置文件
|
||||
└── README.md # 本文档
|
||||
```
|
||||
|
||||
## 功能特性
|
||||
|
||||
- API测试自动化
|
||||
- 支持多种认证方式
|
||||
- 测试用例管理
|
||||
- 测试报告生成(JSON、HTML格式)
|
||||
- 日志记录
|
||||
- 并行测试支持
|
||||
- 测试重试机制
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 安装依赖
|
||||
|
||||
```bash
|
||||
cd test-tools
|
||||
poetry install
|
||||
```
|
||||
|
||||
或者使用pip:
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 配置环境变量
|
||||
|
||||
在项目根目录的`.env`文件中配置test-tools相关环境变量:
|
||||
|
||||
```bash
|
||||
# test-tools API测试配置
|
||||
TEST_TOOLS_API_BASE_URL=http://127.0.0.1:8080/api
|
||||
TEST_TOOLS_API_TIMEOUT=30
|
||||
TEST_TOOLS_API_MAX_RETRIES=3
|
||||
TEST_TOOLS_AUTH_LOGIN_ENDPOINT=/sys/auth/login
|
||||
TEST_TOOLS_AUTH_USERNAME=admin
|
||||
TEST_TOOLS_AUTH_PASSWORD=admin123
|
||||
TEST_TOOLS_AUTH_TOKEN_STORAGE=memory
|
||||
TEST_TOOLS_REPORT_OUTPUT_DIR=test-results/test-tools/reports
|
||||
TEST_TOOLS_LOGGING_LEVEL=INFO
|
||||
TEST_TOOLS_LOGGING_FILE=test-results/test-tools/logs/test.log
|
||||
TEST_TOOLS_LOGGING_CONSOLE=true
|
||||
```
|
||||
|
||||
### 运行测试
|
||||
|
||||
使用npm脚本:
|
||||
|
||||
```bash
|
||||
npm run test:test-tools
|
||||
```
|
||||
|
||||
或者直接运行Python脚本:
|
||||
|
||||
```bash
|
||||
cd test-tools
|
||||
python main.py
|
||||
```
|
||||
|
||||
运行增强版主程序:
|
||||
|
||||
```bash
|
||||
cd test-tools
|
||||
python main_enhanced.py
|
||||
```
|
||||
|
||||
## 配置说明
|
||||
|
||||
### test_config.yaml
|
||||
|
||||
配置文件位于`config/test_config.yaml`,支持环境变量覆盖:
|
||||
|
||||
```yaml
|
||||
api:
|
||||
base_url: ${TEST_TOOLS_API_BASE_URL:http://127.0.0.1:8080/api}
|
||||
timeout: ${TEST_TOOLS_API_TIMEOUT:30}
|
||||
max_retries: ${TEST_TOOLS_API_MAX_RETRIES:3}
|
||||
|
||||
auth:
|
||||
login_endpoint: ${TEST_TOOLS_AUTH_LOGIN_ENDPOINT:/sys/auth/login}
|
||||
username: ${TEST_TOOLS_AUTH_USERNAME:admin}
|
||||
password: ${TEST_TOOLS_AUTH_PASSWORD:admin123}
|
||||
token_storage: ${TEST_TOOLS_AUTH_TOKEN_STORAGE:memory}
|
||||
|
||||
report:
|
||||
output_dir: ${TEST_TOOLS_REPORT_OUTPUT_DIR:../test-results/test-tools/reports}
|
||||
formats:
|
||||
- json
|
||||
- html
|
||||
|
||||
logging:
|
||||
level: ${TEST_TOOLS_LOGGING_LEVEL:INFO}
|
||||
file: ${TEST_TOOLS_LOGGING_FILE:../test-results/test-tools/logs/test.log}
|
||||
console: ${TEST_TOOLS_LOGGING_CONSOLE:true}
|
||||
```
|
||||
|
||||
## 测试报告
|
||||
|
||||
测试报告将生成在`test-results/test-tools/reports/`目录下,支持以下格式:
|
||||
|
||||
- JSON格式:`test_results.json`
|
||||
- HTML格式:`test_results.html`
|
||||
|
||||
日志文件将生成在`test-results/test-tools/logs/`目录下。
|
||||
|
||||
## 集成到主测试项目
|
||||
|
||||
test-tools已集成到主测试项目中,可以通过以下命令统一执行:
|
||||
|
||||
```bash
|
||||
# 执行所有测试(包括test-tools)
|
||||
npm test
|
||||
|
||||
# 只执行test-tools测试
|
||||
npm run test:test-tools
|
||||
|
||||
# 查看test-tools测试报告
|
||||
npm run test:test-tools:report
|
||||
```
|
||||
|
||||
## 开发指南
|
||||
|
||||
### 添加新的测试用例
|
||||
|
||||
1. 在`test_cases/`目录下创建新的测试用例文件
|
||||
2. 按照现有测试用例的格式编写测试代码
|
||||
3. 使用`main.py`或`main_enhanced.py`运行测试
|
||||
|
||||
### 修改配置
|
||||
|
||||
1. 修改`config/test_config.yaml`文件
|
||||
2. 或者在`.env`文件中设置环境变量覆盖配置
|
||||
3. 环境变量优先级高于配置文件
|
||||
|
||||
## 依赖项
|
||||
|
||||
主要依赖项:
|
||||
|
||||
- Python >= 3.10
|
||||
- requests >= 2.31.0
|
||||
- httpx >= 0.25.0
|
||||
- pyyaml >= 6.0
|
||||
- bcrypt >= 4.0.0
|
||||
- psycopg2-binary >= 2.9.0
|
||||
- python-dotenv >= 1.0.0
|
||||
|
||||
开发依赖项:
|
||||
|
||||
- pytest >= 7.4.0
|
||||
- pytest-asyncio >= 0.21.0
|
||||
- pytest-cov >= 4.1.0
|
||||
- black >= 23.0.0
|
||||
- flake8 >= 6.0.0
|
||||
- mypy >= 1.5.0
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 常见问题
|
||||
|
||||
1. **依赖安装失败**
|
||||
- 确保Python版本 >= 3.10
|
||||
- 尝试使用`pip install --upgrade pip`升级pip
|
||||
|
||||
2. **测试执行失败**
|
||||
- 检查API服务是否正常运行
|
||||
- 检查环境变量配置是否正确
|
||||
- 查看日志文件获取详细错误信息
|
||||
|
||||
3. **报告生成失败**
|
||||
- 检查报告输出目录是否有写权限
|
||||
- 确保磁盘空间充足
|
||||
|
||||
## 贡献指南
|
||||
|
||||
欢迎提交问题和改进建议。
|
||||
|
||||
## 许可证
|
||||
|
||||
MIT License
|
||||
Reference in New Issue
Block a user