compliance/tests/test_updated_summary.py
gongwenxin fa343eb111 .
2025-08-07 15:07:38 +08:00

178 lines
7.5 KiB
Python
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.

#!/usr/bin/env python3
"""
测试更新后的摘要内容,包含流程测试信息
"""
import json
import sys
from pathlib import Path
# 添加项目根目录到Python路径
sys.path.insert(0, str(Path(__file__).parent))
from run_api_tests import save_pdf_report
def create_comprehensive_test_data():
"""创建包含完整统计信息的测试数据"""
return {
"start_time": "2025-07-31T10:00:00.000000",
"end_time": "2025-07-31T10:08:45.750000",
"duration_seconds": "525.75",
"overall_summary": {
# 端点统计
"total_endpoints_defined": 12,
"endpoints_tested": 10,
"endpoints_passed": 7,
"endpoints_failed": 2,
"endpoints_error": 0,
"endpoints_skipped": 1,
"endpoint_success_rate": "70.00%",
# 测试用例统计
"total_test_cases_applicable": 150,
"total_test_cases_executed": 48,
"test_cases_passed": 35,
"test_cases_failed": 10,
"test_cases_error": 0,
"test_cases_skipped": 3,
"test_case_success_rate": "72.92%",
# Stage统计
"total_stages_defined": 4,
"total_stages_executed": 3,
"stages_passed": 2,
"stages_failed": 1,
"stages_error": 0,
"stages_skipped": 0,
"stage_success_rate": "66.67%"
},
"endpoint_results": [
{
"endpoint_id": "POST_/api/dms/wb_ml/v1/well_info",
"endpoint_name": "井信息查询服务",
"overall_status": "通过",
"duration_seconds": 0.245,
"executed_test_cases": [
{
"test_case_id": "TC-STATUS-001",
"test_case_name": "基本状态码 200 检查",
"test_case_severity": "CRITICAL",
"status": "通过",
"message": "响应状态码为 200符合预期。"
},
{
"test_case_id": "TC-HEADER-001",
"test_case_name": "必需请求头Schema验证",
"test_case_severity": "HIGH",
"status": "失败",
"message": "缺少必需的请求头 X-Tenant-ID"
}
]
},
{
"endpoint_id": "POST_/api/dms/wb_ml/v1/layer_info",
"endpoint_name": "分层信息表查询服务",
"overall_status": "失败",
"duration_seconds": 0.189,
"executed_test_cases": [
{
"test_case_id": "TC-STATUS-002",
"test_case_name": "基本状态码 200 检查",
"test_case_severity": "CRITICAL",
"status": "失败",
"message": "响应状态码为 500预期为 200"
}
]
}
],
"stage_results": [
{
"stage_id": "dms_crud_scenario_stage",
"stage_name": "DMS Full CRUD Scenario",
"description": "执行完整的Create->Read->Update->Delete->List工作流测试",
"overall_status": "通过",
"duration_seconds": 2.45
},
{
"stage_id": "keyword_driven_crud_stage",
"stage_name": "Keyword Driven CRUD Stage",
"description": "基于关键字驱动的CRUD操作测试阶段",
"overall_status": "通过",
"duration_seconds": 1.85
},
{
"stage_id": "complex_workflow_stage",
"stage_name": "Complex Workflow Stage",
"description": "复杂业务流程测试阶段",
"overall_status": "失败",
"duration_seconds": 3.21
}
]
}
def test_updated_summary():
"""测试更新后的摘要内容"""
print("🧪 测试更新后的摘要内容...")
test_data = create_comprehensive_test_data()
# 显示测试数据统计
overall = test_data['overall_summary']
print("\n📊 测试数据统计:")
print(f"- 端点: 测试{overall['endpoints_tested']}个,通过{overall['endpoints_passed']}个,失败{overall['endpoints_failed']}个,跳过{overall['endpoints_skipped']}")
print(f"- 测试用例: 执行{overall['total_test_cases_executed']}个,通过{overall['test_cases_passed']}个,失败{overall['test_cases_failed']}个,跳过{overall['test_cases_skipped']}")
print(f"- 流程测试: 执行{overall['total_stages_executed']}个,通过{overall['stages_passed']}个,失败{overall['stages_failed']}")
# 生成PDF报告
output_path = Path("test_reports") / "updated_summary_test.pdf"
output_path.parent.mkdir(parents=True, exist_ok=True)
try:
save_pdf_report(test_data, output_path, 'HIGH')
if output_path.exists():
print(f"\n✅ PDF报告生成成功: {output_path}")
print(f"📄 文件大小: {output_path.stat().st_size / 1024:.2f} KB")
print("\n📋 摘要内容现在包含:")
print("✅ 端点测试统计(测试数量、通过、失败、跳过、成功率)")
print("✅ 测试用例统计(执行数量、通过、失败、跳过、成功率)")
print("✅ 流程测试统计(执行数量、通过、失败、跳过、成功率)")
print("✅ 测试时间和总耗时")
# 验证摘要格式
print("\n📝 摘要格式预览:")
print("本次测试针对DMS数据管理系统领域数据服务进行全面的合规性验证。")
print("测试时间2025-07-31 10:00:00 至 2025-07-31 10:08:45总耗时 525.75 秒。")
print(f"共测试 {overall['endpoints_tested']} 个API端点其中 {overall['endpoints_passed']} 个通过,{overall['endpoints_failed']} 个失败,{overall['endpoints_skipped']}个跳过,端点成功率为 {overall['endpoint_success_rate']}")
print(f"执行 {overall['total_test_cases_executed']} 个测试用例,其中 {overall['test_cases_passed']} 个通过,{overall['test_cases_failed']} 个失败,{overall['test_cases_skipped']}个跳过,测试用例成功率为 {overall['test_case_success_rate']}")
print(f"执行 {overall['total_stages_executed']} 个流程测试,其中 {overall['stages_passed']} 个通过,{overall['stages_failed']} 个失败0个跳过流程测试成功率为 {overall['stage_success_rate']}")
else:
print("❌ PDF报告生成失败")
except Exception as e:
print(f"❌ 生成PDF报告时出错: {e}")
import traceback
traceback.print_exc()
def main():
"""主函数"""
print("=" * 70)
print("测试更新后的摘要内容 - 包含流程测试信息")
print("=" * 70)
test_updated_summary()
print("\n" + "=" * 70)
print("🎯 摘要更新完成!")
print("✅ 现在摘要包含完整的三类测试统计:")
print(" 1. API端点测试统计")
print(" 2. 测试用例统计")
print(" 3. 流程测试统计")
print("✅ 每类统计都包含通过、失败、跳过数量和成功率")
print("=" * 70)
if __name__ == "__main__":
main()