Files
张翔 08ea5fbe98 feat(admin): 添加用户管理相关文件
添加用户管理视图、API和状态管理文件
2026-03-28 14:37:29 +08:00

187 lines
4.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Everything is Suitable API Test
黑盒API测试工具,用于对Everything is Suitable API系统执行发布前的质量评估与验证。
## 功能特性
- 测试数据管理:支持JSON、CSV等多种格式的测试用例与测试数据存储
- 内存数据存储:使用内存数据结构管理测试数据,无需数据库
- API测试功能:支持RESTful API的所有HTTP方法(GET、POST、PUT、DELETE等)
- 请求构造:支持请求参数构造、请求头配置、认证授权处理
- 响应验证:支持状态码检查、响应体断言、响应时间阈值验证
- 依赖处理:支持API依赖关系处理与测试用例执行顺序控制
- 测试报告:支持HTML和JSON格式的测试报告,包含可视化图表
- 命令行接口:提供完整的命令行接口,支持测试套件指定和过滤
- 日志记录:实现详细的日志记录系统
## 技术栈
- Python 3.10+
- Poetry(依赖管理)
- requests/httpxHTTP客户端)
- pytest(测试框架)
- Jinja2(模板引擎)
- PyYAML(配置文件解析)
- Click(命令行框架)
## 安装
### 前置要求
- Python 3.10+
- Poetry 1.6.0+
### 安装步骤
1. 克隆项目
```bash
git clone <repository-url>
cd api-test-tool
```
2. 安装依赖
```bash
poetry install
```
3. 配置环境变量(可选)
```bash
export TEST_USERNAME=admin
export TEST_PASSWORD=admin123
```
## 使用
### 基本命令
```bash
# 查看版本
apitest --version
# 查看帮助
apitest --help
# 运行所有测试
apitest run --suite all
# 运行指定模块的测试
apitest run --suite user
# 运行高优先级的测试用例
apitest run --suite all --filter priority=high
# 并发执行测试
apitest run --suite all --parallel --threads 4
# 列出所有测试用例
apitest list --suite all
# 生成测试报告
apitest report --format html --output reports/test.html
# 设置配置
apitest config --set test.parallel=true
# 获取配置
apitest config --get test.parallel
# 验证配置
apitest config --validate
```
### 配置文件
配置文件位于 `config/config.yaml`,包含以下配置项:
- **target**: 目标系统配置(base_url、timeout、max_retries
- **auth**: 认证配置(login_endpoint、username、password、token_storage
- **test**: 测试配置(data_dir、test_cases_dir、parallel、retry_count
- **report**: 报告配置(output_dir、formats、include_details
- **logging**: 日志配置(level、file、format、console
- **data**: 数据管理配置(load_on_startup、auto_refresh、cache_enabled
## 项目结构
```
api-test-tool/
├── src/apitest/ # 源代码
│ ├── models/ # 数据模型
│ ├── client/ # HTTP客户端
│ ├── utils/ # 工具类
│ ├── config/ # 配置管理
│ ├── core/ # 核心功能
│ ├── data/ # 数据管理
│ ├── report/ # 报告生成
│ └── cli/ # 命令行接口
├── data/ # 测试数据
├── test_cases/ # 测试用例
├── reports/ # 测试报告
├── logs/ # 日志文件
├── config/ # 配置文件
├── tests/ # 测试代码
│ ├── unit/ # 单元测试
│ └── integration/ # 集成测试
├── examples/ # 示例代码
├── docs/ # 文档
│ ├── api/ # API文档
│ ├── user/ # 用户手册
│ └── developer/ # 开发指南
├── pyproject.toml # Poetry配置
├── README.md # 项目说明
└── .gitignore # Git忽略文件
```
## 开发
### 代码规范
- 遵循PEP 8代码规范
- 使用类型注解
- 使用Google风格文档字符串
- 代码格式化使用black
- 代码检查使用flake8
- 类型检查使用mypy
### 运行测试
```bash
# 运行所有测试
poetry run pytest
# 运行单元测试
poetry run pytest tests/unit/
# 运行集成测试
poetry run pytest tests/integration/
# 生成覆盖率报告
poetry run pytest --cov=apitest --cov-report=html
```
### 代码格式化
```bash
# 格式化代码
poetry run black src/ tests/
# 检查代码风格
poetry run flake8 src/ tests/
# 类型检查
poetry run mypy src/
```
## 贡献
欢迎贡献代码!请阅读 [CONTRIBUTING.md](CONTRIBUTING.md) 了解贡献指南。
## 许可证
MIT License
## 联系方式
- 项目主页: <repository-url>
- 问题反馈: <issues-url>
- 邮箱: test@example.com