268 lines
5.5 KiB
Markdown
268 lines
5.5 KiB
Markdown
# 测试流程说明
|
||
|
||
## 测试前准备
|
||
|
||
### 1. 检查并安装依赖
|
||
|
||
```bash
|
||
# 检查依赖
|
||
python check_dependencies.py
|
||
|
||
# 如果缺少依赖,安装它们
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
### 2. 配置环境变量
|
||
|
||
创建 `.env` 文件(如果不存在):
|
||
|
||
```env
|
||
# AI服务配置(必需)
|
||
SILICONFLOW_API_KEY=your_api_key_here
|
||
SILICONFLOW_MODEL=deepseek-ai/DeepSeek-V3.2-Exp
|
||
|
||
# 数据库配置(已有默认值)
|
||
DB_HOST=152.136.177.240
|
||
DB_PORT=5012
|
||
DB_USER=finyx
|
||
DB_PASSWORD=6QsGK6MpePZDE57Z
|
||
DB_NAME=finyx
|
||
|
||
# MinIO配置(文档生成需要)
|
||
MINIO_ENDPOINT=minio.datacubeworld.com:9000
|
||
MINIO_ACCESS_KEY=JOLXFXny3avFSzB0uRA5
|
||
MINIO_SECRET_KEY=G1BR8jStNfovkfH5ou39EmPl34E4l7dGrnd3Cz0I
|
||
MINIO_BUCKET=finyx
|
||
MINIO_SECURE=true
|
||
|
||
# 服务配置
|
||
PORT=7500
|
||
DEBUG=False
|
||
```
|
||
|
||
### 3. 初始化数据库(如果还未初始化)
|
||
|
||
```bash
|
||
# 初始化所有字段和配置
|
||
python init_all_fields_from_excel.py
|
||
|
||
# 更新现有配置的template_code字段
|
||
python update_template_code_field.py
|
||
```
|
||
|
||
---
|
||
|
||
## 测试步骤
|
||
|
||
### 步骤 1:检查模块导入
|
||
|
||
```bash
|
||
python test_service.py
|
||
```
|
||
|
||
**预期结果:**
|
||
- ✓ 所有模块导入成功
|
||
- ✓ 字段服务初始化成功
|
||
- ✓ AI服务初始化成功
|
||
|
||
### 步骤 2:启动服务
|
||
|
||
```bash
|
||
python app.py
|
||
```
|
||
|
||
**预期输出:**
|
||
```
|
||
服务启动在 http://localhost:7500
|
||
测试页面: http://localhost:7500/
|
||
Swagger API文档: http://localhost:7500/api-docs
|
||
```
|
||
|
||
### 步骤 3:运行完整测试
|
||
|
||
**在新的终端窗口中运行:**
|
||
|
||
```bash
|
||
python test_complete.py
|
||
```
|
||
|
||
这个脚本会测试:
|
||
1. ✓ 服务连接
|
||
2. ✓ 解析接口
|
||
3. ✓ 文档生成接口(可选)
|
||
4. ✓ API文档页面
|
||
|
||
---
|
||
|
||
## 手动测试
|
||
|
||
### 测试 1:解析接口
|
||
|
||
#### 使用curl
|
||
|
||
```bash
|
||
curl -X POST http://localhost:7500/ai/extract ^
|
||
-H "Content-Type: application/json" ^
|
||
-d "{\"inputData\":[{\"fieldCode\":\"clue_info\",\"fieldValue\":\"被举报用户名称是张三,年龄30岁,某公司总经理,男性,1980年5月出生,中共党员\"}],\"outputData\":[{\"fieldCode\":\"target_name\"},{\"fieldCode\":\"target_gender\"}]}"
|
||
```
|
||
|
||
#### 使用Python
|
||
|
||
```python
|
||
import requests
|
||
import json
|
||
|
||
url = "http://localhost:7500/ai/extract"
|
||
data = {
|
||
"inputData": [
|
||
{
|
||
"fieldCode": "clue_info",
|
||
"fieldValue": "被举报用户名称是张三,年龄30岁,某公司总经理,男性,1980年5月出生,中共党员"
|
||
}
|
||
],
|
||
"outputData": [
|
||
{"fieldCode": "target_name"},
|
||
{"fieldCode": "target_gender"},
|
||
{"fieldCode": "target_organization_and_position"}
|
||
]
|
||
}
|
||
|
||
response = requests.post(url, json=data)
|
||
print(json.dumps(response.json(), ensure_ascii=False, indent=2))
|
||
```
|
||
|
||
#### 预期响应
|
||
|
||
```json
|
||
{
|
||
"code": 0,
|
||
"data": {
|
||
"outData": [
|
||
{
|
||
"fieldCode": "target_name",
|
||
"fieldValue": "张三"
|
||
},
|
||
{
|
||
"fieldCode": "target_gender",
|
||
"fieldValue": "男"
|
||
},
|
||
{
|
||
"fieldCode": "target_organization_and_position",
|
||
"fieldValue": "某公司总经理"
|
||
}
|
||
]
|
||
},
|
||
"msg": "ok",
|
||
"isSuccess": true
|
||
}
|
||
```
|
||
|
||
### 测试 2:文档生成接口
|
||
|
||
**注意:** 此接口需要MinIO配置和模板文件。
|
||
|
||
```bash
|
||
curl -X POST http://localhost:7500/ai/generate-document ^
|
||
-H "Content-Type: application/json" ^
|
||
-d "{\"inputData\":[{\"fieldCode\":\"target_name\",\"fieldValue\":\"张三\"},{\"fieldCode\":\"target_gender\",\"fieldValue\":\"男\"}],\"fpolicFieldParamFileList\":[{\"fileId\":1,\"fileName\":\"测试文档.doc\",\"templateCode\":\"PRELIMINARY_VERIFICATION_APPROVAL\"}]}"
|
||
```
|
||
|
||
### 测试 3:访问Web界面
|
||
|
||
1. 打开浏览器
|
||
2. 访问:http://localhost:7500/
|
||
3. 在测试页面中测试解析功能
|
||
|
||
### 测试 4:查看API文档
|
||
|
||
1. 打开浏览器
|
||
2. 访问:http://localhost:7500/api-docs
|
||
3. 查看接口文档和测试接口
|
||
|
||
---
|
||
|
||
## 常见问题排查
|
||
|
||
### 问题 1:模块导入失败
|
||
|
||
**错误:** `ModuleNotFoundError: No module named 'xxx'`
|
||
|
||
**解决:**
|
||
```bash
|
||
pip install -r requirements.txt
|
||
```
|
||
|
||
### 问题 2:数据库连接失败
|
||
|
||
**错误:** 数据库连接错误
|
||
|
||
**解决:**
|
||
1. 检查数据库配置是否正确
|
||
2. 检查网络连接
|
||
3. 验证数据库服务是否运行
|
||
|
||
### 问题 3:AI解析失败
|
||
|
||
**错误:** `未配置AI服务` 或 API调用失败
|
||
|
||
**解决:**
|
||
1. 检查 `.env` 文件中的 `SILICONFLOW_API_KEY` 是否设置
|
||
2. 验证API密钥是否有效
|
||
3. 检查网络连接
|
||
|
||
### 问题 4:字段查询失败
|
||
|
||
**错误:** `未找到字段编码对应的字段配置`
|
||
|
||
**解决:**
|
||
1. 运行 `python init_all_fields_from_excel.py` 初始化字段
|
||
2. 检查字段编码是否正确
|
||
3. 验证数据库中的字段数据
|
||
|
||
### 问题 5:文档生成失败
|
||
|
||
**错误:** 模板不存在或MinIO连接失败
|
||
|
||
**解决:**
|
||
1. 检查MinIO配置是否正确
|
||
2. 检查模板文件是否存在于MinIO
|
||
3. 验证 `template_code` 是否正确
|
||
4. 检查数据库中的文件配置
|
||
|
||
---
|
||
|
||
## 测试检查清单
|
||
|
||
### 基础功能
|
||
|
||
- [ ] 服务可以正常启动
|
||
- [ ] 所有模块可以正常导入
|
||
- [ ] 数据库连接正常
|
||
- [ ] AI服务配置正确
|
||
|
||
### 接口功能
|
||
|
||
- [ ] 解析接口可以正常调用
|
||
- [ ] 解析接口可以正确提取字段
|
||
- [ ] 文档生成接口可以正常调用(如果配置了MinIO)
|
||
- [ ] 返回格式符合接口文档
|
||
|
||
### 数据验证
|
||
|
||
- [ ] 字段数据已初始化
|
||
- [ ] 文件配置使用template_code字段
|
||
- [ ] 字段查询正常工作
|
||
|
||
---
|
||
|
||
## 下一步
|
||
|
||
测试通过后,可以:
|
||
|
||
1. 部署到测试环境
|
||
2. 进行性能测试
|
||
3. 完善错误处理
|
||
4. 添加更多测试用例
|
||
|
||
|