fix:parser

This commit is contained in:
gongwenxin 2025-08-08 13:59:12 +08:00
parent a472abbd51
commit 66c4e7ff05
4 changed files with 260701 additions and 1065 deletions

View File

@ -621,18 +621,29 @@ class InputParser:
# Find primary key by looking for top-level "identityId" array. # Find primary key by looking for top-level "identityId" array.
identity_id_list = model.get("identityId") identity_id_list = model.get("identityId")
if isinstance(identity_id_list, list) and len(identity_id_list) > 0: if isinstance(identity_id_list, list) and len(identity_id_list) > 0:
pk_name = identity_id_list[0] candidate_pk_name = identity_id_list[0]
self.logger.info(f"Found identityId property '{pk_name}' for model '{name}'.") # 🔧 验证identityId指向的字段是否真的存在于properties中
if candidate_pk_name in model['properties']:
# Fallback to original behavior if no identityId found pk_name = candidate_pk_name
self.logger.info(f"Found identityId property '{pk_name}' for model '{name}'.")
else:
self.logger.warning(f"identityId property '{candidate_pk_name}' not found in model properties for '{name}'. Will use fallback.")
# Fallback to original behavior if no identityId found or identityId field doesn't exist
if not pk_name: if not pk_name:
pk_name = next(iter(model['properties']), None) pk_name = next(iter(model['properties']), None)
if pk_name: if pk_name:
self.logger.warning(f"No 'identityId' array found for model '{name}'. Falling back to using the first property '{pk_name}' as the primary key.") self.logger.warning(f"No valid 'identityId' found for model '{name}'. Falling back to using the first property '{pk_name}' as the primary key.")
if not pk_name: if not pk_name:
self.logger.warning(f"Skipping API '{name}' because no properties found in model to identify a primary key.") self.logger.warning(f"Skipping API '{name}' because no properties found in model to identify a primary key.")
continue continue
# 🔧 再次验证pk_name确实存在于properties中双重保险
if pk_name not in model['properties']:
self.logger.error(f"Critical error: Primary key '{pk_name}' not found in model properties for '{name}'. Skipping this model.")
continue
pk_schema = model['properties'][pk_name] pk_schema = model['properties'][pk_name]
version = model_data.get('version', '1.0.0') version = model_data.get('version', '1.0.0')

View File

@ -1,890 +0,0 @@
{
"summary_metadata": {
"start_time": "2025-05-28T16:49:42.000096",
"end_time": "2025-05-28T16:49:43.454316",
"duration_seconds": "1.45"
},
"endpoint_stats": {
"total_defined": 6,
"total_tested": 6,
"passed": 0,
"failed": 6,
"partial_success": 0,
"error": 0,
"skipped": 0,
"success_rate_percentage": "0.00"
},
"test_case_stats": {
"total_applicable": 42,
"total_executed": 42,
"passed": 24,
"failed": 18,
"error_in_execution": 0,
"skipped_during_endpoint_execution": 0,
"success_rate_percentage": "57.14"
},
"detailed_results": [
{
"endpoint_id": "POST /api/dms/{dms_instance_code}/v1/message/push/{schema}/{version}",
"endpoint_name": "数据推送接口",
"overall_status": "失败",
"duration_seconds": 0.595545,
"start_time": "2025-05-28T16:49:42.000447",
"end_time": "2025-05-28T16:49:42.595992",
"executed_test_cases": [
{
"test_case_id": "TC-STATUS-001",
"test_case_name": "基本状态码 200 检查",
"test_case_severity": "严重",
"status": "通过",
"message": "响应状态码为 200符合预期 200。",
"duration_seconds": 0.3856248748488724,
"timestamp": "2025-05-28T16:49:42.386165",
"validation_points": [
{
"passed": true,
"message": "响应状态码为 200符合预期 200。"
}
]
},
{
"test_case_id": "TC-CORE-FUNC-001",
"test_case_name": "Response Body JSON Schema Validation",
"test_case_severity": "严重",
"status": "通过",
"message": "Schema验证步骤完成未发现问题或schema不适用/未为此响应定义)。",
"duration_seconds": 0.04244487499818206,
"timestamp": "2025-05-28T16:49:42.428768",
"validation_points": [
{
"passed": true,
"message": "Schema验证步骤完成未发现问题或schema不适用/未为此响应定义)。"
}
]
},
{
"test_case_id": "TC-SECURITY-001",
"test_case_name": "HTTPS Protocol Mandatory Verification",
"test_case_severity": "严重",
"status": "失败",
"message": "API通过HTTP (http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/message/push/example_schema/example_version) 响应了成功的状态码 200这违反了HTTPS强制策略。",
"duration_seconds": 0.028596166986972094,
"timestamp": "2025-05-28T16:49:42.457422",
"validation_points": [
{
"status_code": 200
}
]
},
{
"test_case_id": "TC-ERROR-4001-QUERY",
"test_case_name": "Error Code 4001 - Query Parameter Type Mismatch Validation",
"test_case_severity": "中",
"status": "通过",
"message": "跳过测试:在查询参数中未找到合适的字段来测试类型不匹配。",
"duration_seconds": 0.03503883397206664,
"timestamp": "2025-05-28T16:49:42.492537",
"validation_points": [
{
"passed": true,
"message": "跳过测试:在查询参数中未找到合适的字段来测试类型不匹配。"
}
]
},
{
"test_case_id": "TC-ERROR-4001-BODY",
"test_case_name": "Error Code 4001 - Request Body Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当请求体字段 'isSearchCount' 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '39'.",
"duration_seconds": 0.04519999981857836,
"timestamp": "2025-05-28T16:49:42.537838",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 39,
"message": "tempor",
"data": {
"total": 61,
"list": [
{
"dsid": "34",
"dataRegion": "anim incididunt veniam consequat exercitation",
"gasReleaseMon": null,
"gasReleaseYear": null,
"releaseGasCum": null
},
{
"dsid": "35",
"dataRegion": "ex",
"gasReleaseMon": null,
"gasReleaseYear": null,
"releaseGasCum": null
},
{
"dsid": "4",
"dataRegion": "ullamco et",
"gasReleaseMon": null,
"gasReleaseYear": null,
"releaseGasCum": null
}
]
}
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_field": "body.isSearchCount"
}
]
},
{
"test_case_id": "TC-ERROR-4003-BODY",
"test_case_name": "Error Code 4003 - Missing Required Request Body Field Validation",
"test_case_severity": "高",
"status": "通过",
"message": "跳过测试在API规范中未找到合适的必填请求体字段用于移除测试。",
"duration_seconds": 0.027589458972215652,
"timestamp": "2025-05-28T16:49:42.565513",
"validation_points": [
{
"passed": true,
"message": "跳过测试在API规范中未找到合适的必填请求体字段用于移除测试。"
}
]
},
{
"test_case_id": "TC-ERROR-4003-QUERY",
"test_case_name": "Error Code 4003 - Missing Required Query Parameter Validation",
"test_case_severity": "高",
"status": "通过",
"message": "跳过测试在API规范中未找到合适的必填查询参数用于移除测试。",
"duration_seconds": 0.030305457999929786,
"timestamp": "2025-05-28T16:49:42.595953",
"validation_points": [
{
"passed": true,
"message": "跳过测试在API规范中未找到合适的必填查询参数用于移除测试。"
}
]
}
]
},
{
"endpoint_id": "POST /api/dms/{dms_instance_code}/v1/cd_geo_unit/{version}",
"endpoint_name": "地质单元列表查询",
"overall_status": "失败",
"duration_seconds": 0.233222,
"start_time": "2025-05-28T16:49:42.596025",
"end_time": "2025-05-28T16:49:42.829247",
"executed_test_cases": [
{
"test_case_id": "TC-STATUS-001",
"test_case_name": "基本状态码 200 检查",
"test_case_severity": "严重",
"status": "通过",
"message": "响应状态码为 200符合预期 200。",
"duration_seconds": 0.02231612498871982,
"timestamp": "2025-05-28T16:49:42.618421",
"validation_points": [
{
"passed": true,
"message": "响应状态码为 200符合预期 200。"
}
]
},
{
"test_case_id": "TC-CORE-FUNC-001",
"test_case_name": "Response Body JSON Schema Validation",
"test_case_severity": "严重",
"status": "通过",
"message": "Schema验证步骤完成未发现问题或schema不适用/未为此响应定义)。",
"duration_seconds": 0.0266630828846246,
"timestamp": "2025-05-28T16:49:42.645136",
"validation_points": [
{
"passed": true,
"message": "Schema验证步骤完成未发现问题或schema不适用/未为此响应定义)。"
}
]
},
{
"test_case_id": "TC-SECURITY-001",
"test_case_name": "HTTPS Protocol Mandatory Verification",
"test_case_severity": "严重",
"status": "失败",
"message": "API通过HTTP (http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit/1.0.0) 响应了成功的状态码 200这违反了HTTPS强制策略。",
"duration_seconds": 0.06599487503990531,
"timestamp": "2025-05-28T16:49:42.711186",
"validation_points": [
{
"status_code": 200
}
]
},
{
"test_case_id": "TC-ERROR-4001-QUERY",
"test_case_name": "Error Code 4001 - Query Parameter Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当查询参数 'pageNo' (路径: 'pageNo') 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '51'.",
"duration_seconds": 0.03108358313329518,
"timestamp": "2025-05-28T16:49:42.742351",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 51,
"message": "esse sit est pariatur quis",
"data": {
"total": 7,
"list": [
{
"dsid": "52",
"dataRegion": "eu nostrud",
"gasReleaseMon": null,
"gasReleaseYear": null,
"releaseGasCum": null
}
]
}
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_param": "pageNo"
}
]
},
{
"test_case_id": "TC-ERROR-4001-BODY",
"test_case_name": "Error Code 4001 - Request Body Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当请求体字段 'isSearchCount' 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '27'.",
"duration_seconds": 0.02375933318398893,
"timestamp": "2025-05-28T16:49:42.766159",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 27,
"message": "ipsum",
"data": {
"total": 4,
"list": [
{
"dsid": "37",
"dataRegion": "enim officia velit aliqua exercitation",
"gasReleaseMon": null,
"gasReleaseYear": null,
"releaseGasCum": null
}
]
}
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_field": "body.isSearchCount"
}
]
},
{
"test_case_id": "TC-ERROR-4003-BODY",
"test_case_name": "Error Code 4003 - Missing Required Request Body Field Validation",
"test_case_severity": "高",
"status": "通过",
"message": "跳过测试在API规范中未找到合适的必填请求体字段用于移除测试。",
"duration_seconds": 0.03237150004133582,
"timestamp": "2025-05-28T16:49:42.798618",
"validation_points": [
{
"passed": true,
"message": "跳过测试在API规范中未找到合适的必填请求体字段用于移除测试。"
}
]
},
{
"test_case_id": "TC-ERROR-4003-QUERY",
"test_case_name": "Error Code 4003 - Missing Required Query Parameter Validation",
"test_case_severity": "高",
"status": "通过",
"message": "跳过测试在API规范中未找到合适的必填查询参数用于移除测试。",
"duration_seconds": 0.030383124947547913,
"timestamp": "2025-05-28T16:49:42.829203",
"validation_points": [
{
"passed": true,
"message": "跳过测试在API规范中未找到合适的必填查询参数用于移除测试。"
}
]
}
]
},
{
"endpoint_id": "PUT /api/dms/{dms_instance_code}/v1/cd_geo_unit",
"endpoint_name": "地质单元数据修改",
"overall_status": "失败",
"duration_seconds": 0.125734,
"start_time": "2025-05-28T16:49:42.829278",
"end_time": "2025-05-28T16:49:42.955012",
"executed_test_cases": [
{
"test_case_id": "TC-STATUS-001",
"test_case_name": "基本状态码 200 检查",
"test_case_severity": "严重",
"status": "通过",
"message": "响应状态码为 200符合预期 200。",
"duration_seconds": 0.022012750152498484,
"timestamp": "2025-05-28T16:49:42.851563",
"validation_points": [
{
"passed": true,
"message": "响应状态码为 200符合预期 200。"
}
]
},
{
"test_case_id": "TC-CORE-FUNC-001",
"test_case_name": "Response Body JSON Schema Validation",
"test_case_severity": "严重",
"status": "通过",
"message": "针对 PUT http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit (状态码 200) 的响应体 conforms to the JSON schema.",
"duration_seconds": 0.019489916041493416,
"timestamp": "2025-05-28T16:49:42.871101",
"validation_points": [
{
"passed": true,
"message": "针对 PUT http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit (状态码 200) 的响应体 conforms to the JSON schema."
}
]
},
{
"test_case_id": "TC-SECURITY-001",
"test_case_name": "HTTPS Protocol Mandatory Verification",
"test_case_severity": "严重",
"status": "失败",
"message": "API通过HTTP (http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit) 响应了成功的状态码 200这违反了HTTPS强制策略。",
"duration_seconds": 0.016527208033949137,
"timestamp": "2025-05-28T16:49:42.887700",
"validation_points": [
{
"status_code": 200
}
]
},
{
"test_case_id": "TC-ERROR-4001-QUERY",
"test_case_name": "Error Code 4001 - Query Parameter Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当查询参数 'id' (路径: 'id') 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '93'.",
"duration_seconds": 0.021497624926269054,
"timestamp": "2025-05-28T16:49:42.909245",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 93,
"message": "Duis officia",
"data": false
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_param": "id"
}
]
},
{
"test_case_id": "TC-ERROR-4001-BODY",
"test_case_name": "Error Code 4001 - Request Body Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当请求体字段 'id' 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '97'.",
"duration_seconds": 0.014971292112022638,
"timestamp": "2025-05-28T16:49:42.924262",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 97,
"message": "ea proident",
"data": true
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_field": "body.id"
}
]
},
{
"test_case_id": "TC-ERROR-4003-BODY",
"test_case_name": "Error Code 4003 - Missing Required Request Body Field Validation",
"test_case_severity": "高",
"status": "通过",
"message": "当移除必填请求体字段 'id' 时API响应了状态码 200 (非主要预期HTTP状态 [400, 422]但为4xx客户端错误), 且响应体中包含预期的业务错误码 '4003' (字段: 'code').",
"duration_seconds": 0.016076958971098065,
"timestamp": "2025-05-28T16:49:42.940383",
"validation_points": [
{
"passed": true,
"message": "当移除必填请求体字段 'id' 时API响应了状态码 200 (非主要预期HTTP状态 [400, 422]但为4xx客户端错误), 且响应体中包含预期的业务错误码 '4003' (字段: 'code')."
}
]
},
{
"test_case_id": "TC-ERROR-4003-QUERY",
"test_case_name": "Error Code 4003 - Missing Required Query Parameter Validation",
"test_case_severity": "高",
"status": "失败",
"message": "当移除必填查询参数 'id' 时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4003'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '34'.",
"duration_seconds": 0.014534207992255688,
"timestamp": "2025-05-28T16:49:42.954972",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 34,
"message": "commodo consequat velit veniam",
"data": true
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4003",
"removed_param": "query.id"
}
]
}
]
},
{
"endpoint_id": "DELETE /api/dms/{dms_instance_code}/v1/cd_geo_unit",
"endpoint_name": "地质单元数据删除",
"overall_status": "失败",
"duration_seconds": 0.111646,
"start_time": "2025-05-28T16:49:42.955037",
"end_time": "2025-05-28T16:49:43.066683",
"executed_test_cases": [
{
"test_case_id": "TC-STATUS-001",
"test_case_name": "基本状态码 200 检查",
"test_case_severity": "严重",
"status": "通过",
"message": "响应状态码为 200符合预期 200。",
"duration_seconds": 0.016340041998773813,
"timestamp": "2025-05-28T16:49:42.971456",
"validation_points": [
{
"passed": true,
"message": "响应状态码为 200符合预期 200。"
}
]
},
{
"test_case_id": "TC-CORE-FUNC-001",
"test_case_name": "Response Body JSON Schema Validation",
"test_case_severity": "严重",
"status": "通过",
"message": "针对 DELETE http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit (状态码 200) 的响应体 conforms to the JSON schema.",
"duration_seconds": 0.015255250036716461,
"timestamp": "2025-05-28T16:49:42.986761",
"validation_points": [
{
"passed": true,
"message": "针对 DELETE http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit (状态码 200) 的响应体 conforms to the JSON schema."
}
]
},
{
"test_case_id": "TC-SECURITY-001",
"test_case_name": "HTTPS Protocol Mandatory Verification",
"test_case_severity": "严重",
"status": "失败",
"message": "API通过HTTP (http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit) 响应了成功的状态码 200这违反了HTTPS强制策略。",
"duration_seconds": 0.019025625195354223,
"timestamp": "2025-05-28T16:49:43.005840",
"validation_points": [
{
"status_code": 200
}
]
},
{
"test_case_id": "TC-ERROR-4001-QUERY",
"test_case_name": "Error Code 4001 - Query Parameter Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当查询参数 'id' (路径: 'id') 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '44'.",
"duration_seconds": 0.015513875056058168,
"timestamp": "2025-05-28T16:49:43.021404",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 44,
"message": "culpa",
"data": true
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_param": "id"
}
]
},
{
"test_case_id": "TC-ERROR-4001-BODY",
"test_case_name": "Error Code 4001 - Request Body Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当请求体字段 'version' 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '62'.",
"duration_seconds": 0.014269457897171378,
"timestamp": "2025-05-28T16:49:43.035721",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 62,
"message": "nisi id Ut est",
"data": false
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_field": "body.version"
}
]
},
{
"test_case_id": "TC-ERROR-4003-BODY",
"test_case_name": "Error Code 4003 - Missing Required Request Body Field Validation",
"test_case_severity": "高",
"status": "通过",
"message": "跳过测试在API规范中未找到合适的必填请求体字段用于移除测试。",
"duration_seconds": 0.014604958007112145,
"timestamp": "2025-05-28T16:49:43.050373",
"validation_points": [
{
"passed": true,
"message": "跳过测试在API规范中未找到合适的必填请求体字段用于移除测试。"
}
]
},
{
"test_case_id": "TC-ERROR-4003-QUERY",
"test_case_name": "Error Code 4003 - Missing Required Query Parameter Validation",
"test_case_severity": "高",
"status": "失败",
"message": "当移除必填查询参数 'id' 时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4003'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '75'.",
"duration_seconds": 0.016156750032678246,
"timestamp": "2025-05-28T16:49:43.066589",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 75,
"message": "sint tempor laboris proident irure",
"data": true
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4003",
"removed_param": "query.id"
}
]
}
]
},
{
"endpoint_id": "POST /api/dms/{dms_instance_code}/v1/cd_geo_unit",
"endpoint_name": "地质单元数据添加",
"overall_status": "失败",
"duration_seconds": 0.258948,
"start_time": "2025-05-28T16:49:43.066754",
"end_time": "2025-05-28T16:49:43.325702",
"executed_test_cases": [
{
"test_case_id": "TC-STATUS-001",
"test_case_name": "基本状态码 200 检查",
"test_case_severity": "严重",
"status": "通过",
"message": "响应状态码为 200符合预期 200。",
"duration_seconds": 0.017587749985978007,
"timestamp": "2025-05-28T16:49:43.084674",
"validation_points": [
{
"passed": true,
"message": "响应状态码为 200符合预期 200。"
}
]
},
{
"test_case_id": "TC-CORE-FUNC-001",
"test_case_name": "Response Body JSON Schema Validation",
"test_case_severity": "严重",
"status": "通过",
"message": "Schema验证步骤完成未发现问题或schema不适用/未为此响应定义)。",
"duration_seconds": 0.019916499964892864,
"timestamp": "2025-05-28T16:49:43.104648",
"validation_points": [
{
"passed": true,
"message": "Schema验证步骤完成未发现问题或schema不适用/未为此响应定义)。"
}
]
},
{
"test_case_id": "TC-SECURITY-001",
"test_case_name": "HTTPS Protocol Mandatory Verification",
"test_case_severity": "严重",
"status": "失败",
"message": "API通过HTTP (http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit) 响应了成功的状态码 200这违反了HTTPS强制策略。",
"duration_seconds": 0.014826040947809815,
"timestamp": "2025-05-28T16:49:43.119607",
"validation_points": [
{
"status_code": 200
}
]
},
{
"test_case_id": "TC-ERROR-4001-QUERY",
"test_case_name": "Error Code 4001 - Query Parameter Type Mismatch Validation",
"test_case_severity": "中",
"status": "通过",
"message": "跳过测试:在查询参数中未找到合适的字段来测试类型不匹配。",
"duration_seconds": 0.01400312501937151,
"timestamp": "2025-05-28T16:49:43.133661",
"validation_points": [
{
"passed": true,
"message": "跳过测试:在查询参数中未找到合适的字段来测试类型不匹配。"
}
]
},
{
"test_case_id": "TC-ERROR-4001-BODY",
"test_case_name": "Error Code 4001 - Request Body Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当请求体字段 'version' 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '99'.",
"duration_seconds": 0.015632750000804663,
"timestamp": "2025-05-28T16:49:43.149338",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 99,
"message": "cupidatat",
"data": true
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_field": "body.version"
}
]
},
{
"test_case_id": "TC-ERROR-4003-BODY",
"test_case_name": "Error Code 4003 - Missing Required Request Body Field Validation",
"test_case_severity": "高",
"status": "失败",
"message": "当移除必填请求体字段 'data.0.bsflag' 时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4003'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '48'.",
"duration_seconds": 0.07669858285225928,
"timestamp": "2025-05-28T16:49:43.226093",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 48,
"message": "qui",
"data": false
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4003",
"removed_field": "body.data.0.bsflag"
}
]
},
{
"test_case_id": "TC-ERROR-4003-QUERY",
"test_case_name": "Error Code 4003 - Missing Required Query Parameter Validation",
"test_case_severity": "高",
"status": "通过",
"message": "跳过测试在API规范中未找到合适的必填查询参数用于移除测试。",
"duration_seconds": 0.09806604101322591,
"timestamp": "2025-05-28T16:49:43.325657",
"validation_points": [
{
"passed": true,
"message": "跳过测试在API规范中未找到合适的必填查询参数用于移除测试。"
}
]
}
]
},
{
"endpoint_id": "GET /api/dms/{dms_instance_code}/v1/cd_geo_unit/{version}/{id}",
"endpoint_name": "地质单元查询详情",
"overall_status": "失败",
"duration_seconds": 0.128568,
"start_time": "2025-05-28T16:49:43.325730",
"end_time": "2025-05-28T16:49:43.454298",
"executed_test_cases": [
{
"test_case_id": "TC-STATUS-001",
"test_case_name": "基本状态码 200 检查",
"test_case_severity": "严重",
"status": "通过",
"message": "响应状态码为 200符合预期 200。",
"duration_seconds": 0.020079500041902065,
"timestamp": "2025-05-28T16:49:43.345893",
"validation_points": [
{
"passed": true,
"message": "响应状态码为 200符合预期 200。"
}
]
},
{
"test_case_id": "TC-CORE-FUNC-001",
"test_case_name": "Response Body JSON Schema Validation",
"test_case_severity": "严重",
"status": "通过",
"message": "针对 GET http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit/1.0.0/example_id (状态码 200) 的响应体 conforms to the JSON schema.",
"duration_seconds": 0.015128917060792446,
"timestamp": "2025-05-28T16:49:43.361072",
"validation_points": [
{
"passed": true,
"message": "针对 GET http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit/1.0.0/example_id (状态码 200) 的响应体 conforms to the JSON schema."
}
]
},
{
"test_case_id": "TC-SECURITY-001",
"test_case_name": "HTTPS Protocol Mandatory Verification",
"test_case_severity": "严重",
"status": "失败",
"message": "API通过HTTP (http://127.0.0.1:4523/m1/6389742-6086420-default/api/dms/example_dms_instance_code/v1/cd_geo_unit/1.0.0/example_id) 响应了成功的状态码 200这违反了HTTPS强制策略。",
"duration_seconds": 0.015682624885812402,
"timestamp": "2025-05-28T16:49:43.376817",
"validation_points": [
{
"status_code": 200
}
]
},
{
"test_case_id": "TC-ERROR-4001-QUERY",
"test_case_name": "Error Code 4001 - Query Parameter Type Mismatch Validation",
"test_case_severity": "中",
"status": "通过",
"message": "跳过测试:在查询参数中未找到合适的字段来测试类型不匹配。",
"duration_seconds": 0.015055665979161859,
"timestamp": "2025-05-28T16:49:43.391929",
"validation_points": [
{
"passed": true,
"message": "跳过测试:在查询参数中未找到合适的字段来测试类型不匹配。"
}
]
},
{
"test_case_id": "TC-ERROR-4001-BODY",
"test_case_name": "Error Code 4001 - Request Body Type Mismatch Validation",
"test_case_severity": "中",
"status": "失败",
"message": "当请求体字段 'isSearchCount' 类型不匹配时期望API返回状态码在 [400, 422] 中或返回4xx客户端错误且业务码为 '4001'. 实际收到状态码 200. 响应体中的业务码 ('code') 为 '74'.",
"duration_seconds": 0.01596312504261732,
"timestamp": "2025-05-28T16:49:43.407948",
"validation_points": [
{
"status_code": 200,
"response_body": {
"code": 74,
"message": "ipsum commodo dolore",
"data": {
"total": 100,
"list": [
{
"dsid": "47",
"dataRegion": "dolore aute Lorem",
"gasReleaseMon": null,
"gasReleaseYear": null,
"releaseGasCum": null
}
]
}
},
"expected_http_status_codes": [
400,
422
],
"expected_business_code": "4001",
"mismatched_field": "body.isSearchCount"
}
]
},
{
"test_case_id": "TC-ERROR-4003-BODY",
"test_case_name": "Error Code 4003 - Missing Required Request Body Field Validation",
"test_case_severity": "高",
"status": "通过",
"message": "跳过测试在API规范中未找到合适的必填请求体字段用于移除测试。",
"duration_seconds": 0.017927916953340173,
"timestamp": "2025-05-28T16:49:43.425926",
"validation_points": [
{
"passed": true,
"message": "跳过测试在API规范中未找到合适的必填请求体字段用于移除测试。"
}
]
},
{
"test_case_id": "TC-ERROR-4003-QUERY",
"test_case_name": "Error Code 4003 - Missing Required Query Parameter Validation",
"test_case_severity": "高",
"status": "通过",
"message": "跳过测试在API规范中未找到合适的必填查询参数用于移除测试。",
"duration_seconds": 0.028265791945159435,
"timestamp": "2025-05-28T16:49:43.454254",
"validation_points": [
{
"passed": true,
"message": "跳过测试在API规范中未找到合适的必填查询参数用于移除测试。"
}
]
}
]
}
]
}

260685
summary(4).json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,170 +0,0 @@
#!/usr/bin/env python3
"""
验证PDF报告中的失败用例详情
"""
import json
import sys
from pathlib import Path
from run_api_tests import save_pdf_report
def verify_latest_report():
"""验证最新的测试报告"""
print("🔍 验证最新测试报告的PDF失败用例详情")
print("=" * 60)
# 找到最新的测试报告目录
test_reports_dir = Path("test_reports")
if not test_reports_dir.exists():
print("❌ 测试报告目录不存在")
return False
# 获取所有日期格式的目录
date_dirs = [d for d in test_reports_dir.iterdir()
if d.is_dir() and d.name.startswith("2025-")]
if not date_dirs:
print("❌ 没有找到测试报告目录")
return False
# 找到最新的目录
latest_dir = max(date_dirs, key=lambda x: x.name)
print(f"📁 最新测试报告目录: {latest_dir}")
# 读取JSON摘要
json_file = latest_dir / "summary.json"
if not json_file.exists():
print(f"❌ 找不到摘要文件: {json_file}")
return False
try:
with open(json_file, 'r', encoding='utf-8') as f:
test_data = json.load(f)
except Exception as e:
print(f"❌ 读取摘要文件失败: {e}")
return False
# 分析失败用例
failed_cases = []
endpoint_results = test_data.get('endpoint_results', [])
for endpoint in endpoint_results:
test_cases = endpoint.get('executed_test_cases', [])
for tc in test_cases:
if tc.get('status') in ['失败', 'FAILED']:
failed_cases.append({
'endpoint': endpoint.get('endpoint_name', 'N/A'),
'case_id': tc.get('test_case_id', 'N/A'),
'case_name': tc.get('test_case_name', 'N/A'),
'severity': tc.get('test_case_severity', 'N/A'),
'message': tc.get('message', 'N/A')
})
# 分析stage失败用例
stage_results = test_data.get('stage_results', [])
for stage in stage_results:
if stage.get('overall_status') in ['失败', 'FAILED']:
failed_cases.append({
'endpoint': f"Stage: {stage.get('stage_name', 'N/A')}",
'case_id': f"STAGE_{stage.get('stage_name', 'N/A')}",
'case_name': stage.get('description', stage.get('stage_name', 'N/A')),
'severity': 'HIGH',
'message': stage.get('message', stage.get('error_message', 'N/A'))
})
print(f"📊 测试数据统计:")
print(f"- 总端点数: {test_data.get('overall_summary', {}).get('endpoints_tested', 0)}")
print(f"- 总测试用例: {test_data.get('overall_summary', {}).get('total_test_cases_executed', 0)}")
print(f"- 失败用例数: {len(failed_cases)}")
print(f"- 测试成功率: {test_data.get('overall_summary', {}).get('test_case_success_rate', 'N/A')}")
if failed_cases:
print(f"\n📋 失败用例详情:")
for i, case in enumerate(failed_cases, 1):
print(f"{i}. {case['case_name']} ({case['case_id']})")
print(f" 端点: {case['endpoint']}")
print(f" 严重级别: {case['severity']}")
print(f" 失败原因: {case['message'][:100]}...")
print()
# 重新生成PDF报告以验证失败用例详情
pdf_file = latest_dir / "report_cn.pdf"
print(f"🔄 重新生成PDF报告: {pdf_file}")
try:
save_pdf_report(test_data, pdf_file, strictness_level='HIGH')
if pdf_file.exists():
file_size = pdf_file.stat().st_size / 1024
print(f"✅ PDF报告生成成功!")
print(f"📄 文件大小: {file_size:.2f} KB")
print(f"\n🎯 PDF报告现在包含以下新功能:")
print("✅ 失败用例详情分析部分")
print("✅ 按严重级别分组的失败统计")
print("✅ 每个失败用例的详细信息:")
print(" - 用例ID和名称")
print(" - 所属端点")
print(" - 严重级别")
print(" - 详细的失败原因")
if failed_cases:
print(f"\n📝 报告中将显示 {len(failed_cases)} 个失败用例的详细分析")
# 按严重级别分组
critical_count = len([c for c in failed_cases if c['severity'] == 'CRITICAL'])
high_count = len([c for c in failed_cases if c['severity'] == 'HIGH'])
medium_count = len([c for c in failed_cases if c['severity'] == 'MEDIUM'])
low_count = len([c for c in failed_cases if c['severity'] == 'LOW'])
print(f" - 严重级别: {critical_count}")
print(f" - 高级别: {high_count}")
print(f" - 中级别: {medium_count}")
print(f" - 低级别: {low_count}")
else:
print("✅ 本次测试没有失败用例")
return True
else:
print("❌ PDF报告生成失败")
return False
except Exception as e:
print(f"❌ 生成PDF报告时出错: {e}")
import traceback
traceback.print_exc()
return False
def main():
"""主函数"""
print("🚀 DMS合规性测试工具 - PDF失败用例详情验证")
print("=" * 80)
success = verify_latest_report()
print("\n" + "=" * 80)
if success:
print("🎉 验证完成PDF报告已成功添加失败用例详情功能")
print("\n💡 新功能说明:")
print("1. 在PDF报告中新增了'失败用例详情分析'部分")
print("2. 按严重级别统计和分组显示失败用例")
print("3. 每个失败用例都包含:")
print(" - 用例基本信息ID、名称、端点、严重级别")
print(" - 详细的失败原因说明")
print(" - 清晰的格式化显示")
print("4. 支持endpoint测试用例和stage测试用例")
print("5. 自动处理长文本确保PDF显示正常")
print("\n📖 使用方法:")
print("- 运行测试后查看生成的PDF报告")
print("- 在报告中找到'失败用例详情分析'部分")
print("- 每个失败用例都有详细的错误信息和修复建议")
sys.exit(0)
else:
print("❌ 验证失败,请检查错误信息")
sys.exit(1)
if __name__ == "__main__":
main()