all in
This commit is contained in:
@@ -0,0 +1,280 @@
|
||||
"""
|
||||
文档列表综合测试 - 搜索过滤 + 完整数据展示
|
||||
结合 test_search_filters.py 和 test_all_documents.py 的功能
|
||||
"""
|
||||
import sys
|
||||
import io
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||||
|
||||
# 配置
|
||||
BASE_URL = "http://localhost:8073/admin/api/v3"
|
||||
ADMIN_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjo1LCJ1c2VybmFtZSI6ImFkbWluIiwidXNlcl9yb2xlIjoiYWRtaW4iLCJleHAiOjE3NjM1NDAwMTksImlhdCI6MTc2MzUxODQxOSwiaXNzdWVkX3RpbWUiOiIyMDI1LTExLTE5IDEwOjEzOjM5IiwiYXVkIjoiZG9jcmV2aWV3LWZyb250ZW5kIiwic3ViIjoiMDAwIiwibmlja19uYW1lIjoiYWRtaW4iLCJvdV9pZCI6IjAwMCIsIm91X25hbWUiOiJ0ZXN0IiwiaXNfbGVhZGVyIjp0cnVlfQ.Mocax00w0Os4n2WjogOk5kwE-KYkR4AfGTGA33sjgc0"
|
||||
|
||||
# ANSI颜色
|
||||
GREEN = '\033[92m'
|
||||
RED = '\033[91m'
|
||||
YELLOW = '\033[93m'
|
||||
BLUE = '\033[94m'
|
||||
CYAN = '\033[96m'
|
||||
MAGENTA = '\033[95m'
|
||||
RESET = '\033[0m'
|
||||
BOLD = '\033[1m'
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {ADMIN_TOKEN}",
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
def print_header(text: str):
|
||||
print(f"\n{BLUE}{BOLD}{'='*100}{RESET}")
|
||||
print(f"{BLUE}{BOLD}{text:^100}{RESET}")
|
||||
print(f"{BLUE}{BOLD}{'='*100}{RESET}")
|
||||
|
||||
def print_subheader(text: str):
|
||||
print(f"\n{CYAN}{'-'*100}{RESET}")
|
||||
print(f"{CYAN}{text}{RESET}")
|
||||
print(f"{CYAN}{'-'*100}{RESET}")
|
||||
|
||||
def test_scenario(title: str, params: dict, show_full_json: bool = False, show_details: bool = True):
|
||||
"""
|
||||
测试场景:执行搜索并展示结果
|
||||
|
||||
Args:
|
||||
title: 测试场景标题
|
||||
params: 查询参数
|
||||
show_full_json: 是否显示完整JSON
|
||||
show_details: 是否显示详细信息
|
||||
"""
|
||||
print_header(f"📋 {title}")
|
||||
|
||||
# 显示查询参数
|
||||
print(f"\n{CYAN}🔍 查询参数:{RESET}")
|
||||
for key, value in params.items():
|
||||
print(f" • {key}: {value}")
|
||||
|
||||
# 执行请求
|
||||
url = f"{BASE_URL}/versions/documents-list"
|
||||
start_time = time.time()
|
||||
response = requests.get(url, headers=headers, params=params)
|
||||
elapsed = time.time() - start_time
|
||||
|
||||
# 状态码
|
||||
if response.status_code == 200:
|
||||
print(f"\n{GREEN}✓ 请求成功{RESET} - 状态码: {response.status_code} - 耗时: {elapsed*1000:.0f}ms")
|
||||
else:
|
||||
print(f"\n{RED}✗ 请求失败{RESET} - 状态码: {response.status_code}")
|
||||
print(f"{RED}{response.text}{RESET}")
|
||||
return
|
||||
|
||||
data = response.json()
|
||||
documents = data.get("documents", [])
|
||||
total = data.get("total", 0)
|
||||
|
||||
# 基本统计
|
||||
print(f"\n{CYAN}📊 查询结果统计:{RESET}")
|
||||
print(f" • 总文档数: {total}")
|
||||
print(f" • 当前页: {data.get('page', 0)}/{data.get('total_pages', 0)}")
|
||||
print(f" • 每页数量: {data.get('page_size', 0)}")
|
||||
print(f" • 返回文档数: {len(documents)}")
|
||||
|
||||
if len(documents) == 0:
|
||||
print(f"\n{YELLOW}⚠ 未找到任何文档{RESET}")
|
||||
return
|
||||
|
||||
# 显示文档列表
|
||||
print(f"\n{CYAN}📄 文档列表:{RESET}")
|
||||
for idx, doc in enumerate(documents, 1):
|
||||
name = doc.get('name', 'N/A')
|
||||
status = doc.get('status', 'N/A')
|
||||
audit = doc.get('audit_status', 'N/A')
|
||||
version = doc.get('version_number', 'N/A')
|
||||
total_ver = doc.get('total_versions', 'N/A')
|
||||
|
||||
# 审核状态颜色
|
||||
audit_color = RESET
|
||||
if audit == 1:
|
||||
audit_color = GREEN
|
||||
elif audit == 0:
|
||||
audit_color = YELLOW
|
||||
elif audit in [-1, -2]:
|
||||
audit_color = RED
|
||||
|
||||
print(f" {idx}. {name}")
|
||||
print(f" └─ 状态:{status} | 审核:{audit_color}{audit}{RESET} | 版本:v{version}/{total_ver}")
|
||||
|
||||
# 详细信息
|
||||
if show_details:
|
||||
print_subheader("📖 文档详细信息")
|
||||
for idx, doc in enumerate(documents, 1):
|
||||
print(f"\n{MAGENTA}{BOLD}▼ 文档 {idx}: {doc.get('name')}{RESET}")
|
||||
|
||||
# 基本信息
|
||||
print(f"\n {CYAN}📄 基本信息:{RESET}")
|
||||
print(f" • ID: {doc.get('id')}")
|
||||
print(f" • 文件大小: {doc.get('file_size', 0):,} bytes ({doc.get('file_size', 0)/1024/1024:.2f} MB)")
|
||||
print(f" • 创建时间: {doc.get('created_at')}")
|
||||
print(f" • 上传时间: {doc.get('upload_time')}")
|
||||
print(f" • 文档类型ID: {doc.get('type_id')}")
|
||||
|
||||
# 评查统计
|
||||
print(f"\n {CYAN}📊 评查统计:{RESET}")
|
||||
print(f" • 总评查点: {doc.get('total_evaluation_points', 0)}")
|
||||
print(f" • {GREEN}通过: {doc.get('pass_count', 0)}{RESET}")
|
||||
print(f" • {YELLOW}警告: {doc.get('warning_count', 0)}{RESET}")
|
||||
print(f" • {RED}错误: {doc.get('error_count', 0)}{RESET}")
|
||||
print(f" • {MAGENTA}需人工: {doc.get('manual_count', 0)}{RESET}")
|
||||
print(f" • {CYAN}问题总数: {doc.get('issue_count', 0)}{RESET}")
|
||||
|
||||
# 版本信息
|
||||
history = doc.get('history_versions', [])
|
||||
print(f"\n {CYAN}📚 版本信息:{RESET}")
|
||||
print(f" • 当前版本: v{doc.get('version_number')}")
|
||||
print(f" • 总版本数: {doc.get('total_versions')}")
|
||||
print(f" • 历史版本数: {len(history)}")
|
||||
|
||||
if len(history) > 0:
|
||||
for h_idx, h_ver in enumerate(history, 1):
|
||||
print(f" └─ 历史 {h_idx}: v{h_ver.get('version_number')} (ID:{h_ver.get('id')})")
|
||||
print(f" ├─ 创建: {h_ver.get('created_at')}")
|
||||
print(f" ├─ 评查: {GREEN}{h_ver.get('pass_count', 0)}通过{RESET} / {YELLOW}{h_ver.get('warning_count', 0)}警告{RESET} / {RED}{h_ver.get('error_count', 0)}错误{RESET}")
|
||||
print(f" └─ 问题: {h_ver.get('issue_count', 0)}个")
|
||||
|
||||
# 问题消息
|
||||
warning_msgs = doc.get('warning_messages', [])
|
||||
error_msgs = doc.get('error_messages', [])
|
||||
manual_msgs = doc.get('manual_messages', [])
|
||||
|
||||
if len(warning_msgs) > 0:
|
||||
print(f"\n {YELLOW}⚠️ 警告消息 ({len(warning_msgs)}条):{RESET}")
|
||||
for i, msg in enumerate(warning_msgs[:3], 1): # 只显示前3条
|
||||
print(f" {i}. {msg}")
|
||||
if len(warning_msgs) > 3:
|
||||
print(f" ... 还有 {len(warning_msgs) - 3} 条警告")
|
||||
|
||||
if len(error_msgs) > 0:
|
||||
print(f"\n {RED}❌ 错误消息 ({len(error_msgs)}条):{RESET}")
|
||||
for i, msg in enumerate(error_msgs, 1):
|
||||
print(f" {i}. {msg}")
|
||||
|
||||
if len(manual_msgs) > 0:
|
||||
print(f"\n {MAGENTA}👤 人工确认消息 ({len(manual_msgs)}条):{RESET}")
|
||||
for i, msg in enumerate(manual_msgs[:3], 1): # 只显示前3条
|
||||
print(f" {i}. {msg}")
|
||||
if len(manual_msgs) > 3:
|
||||
print(f" ... 还有 {len(manual_msgs) - 3} 条消息")
|
||||
|
||||
# 显示完整JSON
|
||||
if show_full_json:
|
||||
print_subheader("📝 完整JSON响应")
|
||||
print(json.dumps(data, indent=2, ensure_ascii=False))
|
||||
|
||||
print(f"\n{GREEN}{'─'*100}{RESET}")
|
||||
|
||||
|
||||
def main():
|
||||
"""主测试流程"""
|
||||
print_header("🔬 文档列表API综合测试套件")
|
||||
print(f"{CYAN}测试时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}{RESET}\n")
|
||||
|
||||
# 定义测试场景
|
||||
test_scenarios = [
|
||||
{
|
||||
"title": "测试1: 获取所有文档",
|
||||
"params": {"page": 1, "page_size": 10},
|
||||
"show_details": True,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试2: 文档名称搜索(包含'第')",
|
||||
"params": {"page": 1, "page_size": 10, "name": "第"},
|
||||
"show_details": False,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试3: 文件状态过滤(已完成)",
|
||||
"params": {"page": 1, "page_size": 10, "status": "Processed"},
|
||||
"show_details": False,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试4: 审核状态过滤(待审核=0)",
|
||||
"params": {"page": 1, "page_size": 10, "audit_status": 0},
|
||||
"show_details": True,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试5: 审核状态过滤(通过=1)",
|
||||
"params": {"page": 1, "page_size": 10, "audit_status": 1},
|
||||
"show_details": False,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试6: 时间范围(今天)",
|
||||
"params": {
|
||||
"page": 1,
|
||||
"page_size": 10,
|
||||
"start_time": datetime.now().strftime("%Y-%m-%d"),
|
||||
"end_time": datetime.now().strftime("%Y-%m-%d")
|
||||
},
|
||||
"show_details": False,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试7: 时间范围(最近7天)",
|
||||
"params": {
|
||||
"page": 1,
|
||||
"page_size": 10,
|
||||
"start_time": (datetime.now() - timedelta(days=7)).strftime("%Y-%m-%d"),
|
||||
"end_time": datetime.now().strftime("%Y-%m-%d")
|
||||
},
|
||||
"show_details": False,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试8: 文档类型过滤(type_id=3)",
|
||||
"params": {"page": 1, "page_size": 10, "type_id": 3},
|
||||
"show_details": False,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试9: 组合过滤(名称+状态+审核)",
|
||||
"params": {
|
||||
"page": 1,
|
||||
"page_size": 10,
|
||||
"name": "pdf",
|
||||
"status": "Processed",
|
||||
"audit_status": 2
|
||||
},
|
||||
"show_details": False,
|
||||
"show_full_json": False
|
||||
},
|
||||
{
|
||||
"title": "测试10: 完整JSON输出示例",
|
||||
"params": {"page": 1, "page_size": 2},
|
||||
"show_details": False,
|
||||
"show_full_json": True
|
||||
}
|
||||
]
|
||||
|
||||
# 执行所有测试
|
||||
for scenario in test_scenarios:
|
||||
test_scenario(
|
||||
scenario["title"],
|
||||
scenario["params"],
|
||||
scenario.get("show_full_json", False),
|
||||
scenario.get("show_details", True)
|
||||
)
|
||||
print() # 空行分隔
|
||||
|
||||
# 汇总
|
||||
print_header("✅ 所有测试完成")
|
||||
print(f"{GREEN}共执行 {len(test_scenarios)} 个测试场景{RESET}\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user