add:stage
This commit is contained in:
Binary file not shown.
@@ -16,56 +16,44 @@ class PaginationParamsCheckTestCase(BaseAPITestCase):
|
||||
# 这个测试用例不需要发送实际请求
|
||||
skip_execution = True
|
||||
|
||||
@classmethod
|
||||
def applies_to(cls, endpoint_spec: Dict[str, Any], **kwargs) -> bool:
|
||||
"""
|
||||
此测试用例仅适用于满足以下条件的端点:
|
||||
1. 是GET或POST方法。
|
||||
2. API描述中包含分页相关的关键词(如'查询', '列表')。
|
||||
3. API描述中不包含排除的关键词(如'详情')。
|
||||
"""
|
||||
path = endpoint_spec.get('path', '')
|
||||
method = endpoint_spec.get('method', '').lower()
|
||||
|
||||
if method not in ['get', 'post']:
|
||||
return False
|
||||
|
||||
summary = endpoint_spec.get('summary', '')
|
||||
description = endpoint_spec.get('description', '')
|
||||
operation_id = endpoint_spec.get('operationId', '')
|
||||
|
||||
include_keywords = ["查询", "列表", "分页", "page", "list", "query", "search", "find"]
|
||||
exclude_keywords = ["详情", "明细", "detail", "info", "get", "查看"]
|
||||
|
||||
api_description_text = f"{summary} {description} {operation_id} {path}".lower()
|
||||
|
||||
contains_include_keyword = any(keyword.lower() in api_description_text for keyword in include_keywords)
|
||||
contains_exclude_keyword = any(keyword.lower() in api_description_text for keyword in exclude_keywords)
|
||||
|
||||
return contains_include_keyword and not contains_exclude_keyword
|
||||
|
||||
def __init__(self, endpoint_spec: Dict[str, Any], global_api_spec: Dict[str, Any], json_schema_validator: Optional[Any] = None, llm_service: Optional[Any] = None):
|
||||
super().__init__(endpoint_spec, global_api_spec, json_schema_validator, llm_service=llm_service)
|
||||
|
||||
# 定义需要验证的API名称关键词
|
||||
self.include_keywords = ["查询", "列表", "分页", "page", "list", "query", "search", "find"]
|
||||
# 定义排除的API名称关键词
|
||||
self.exclude_keywords = ["详情", "明细", "detail", "info", "get", "查看"]
|
||||
|
||||
def validate_response(self, response_context: APIResponseContext, request_context: APIRequestContext) -> List[ValidationResult]:
|
||||
"""
|
||||
检查API请求中是否包含标准分页参数
|
||||
"""
|
||||
results = []
|
||||
|
||||
# 获取API路径和方法
|
||||
path = self.endpoint_spec.get('path', '')
|
||||
method = self.endpoint_spec.get('method', '').lower()
|
||||
|
||||
# 获取API的摘要和描述信息
|
||||
summary = self.endpoint_spec.get('summary', '')
|
||||
description = self.endpoint_spec.get('description', '')
|
||||
operation_id = self.endpoint_spec.get('operationId', '')
|
||||
|
||||
# 组合所有可能包含API名称或功能描述的字段
|
||||
api_description_text = f"{summary} {description} {operation_id} {path}".lower()
|
||||
|
||||
# 检查是否包含需要验证的关键词,且不包含排除的关键词
|
||||
contains_include_keyword = any(keyword.lower() in api_description_text for keyword in self.include_keywords)
|
||||
contains_exclude_keyword = any(keyword.lower() in api_description_text for keyword in self.exclude_keywords)
|
||||
|
||||
# 如果不满足准入规则,直接返回通过
|
||||
if not contains_include_keyword or contains_exclude_keyword:
|
||||
results.append(self.passed(
|
||||
message=f"跳过检查:API不符合分页参数检查的准入规则(需包含'查询'/'列表'等关键词,且不包含'详情'等关键词)",
|
||||
details={
|
||||
"path": path,
|
||||
"method": method.upper(),
|
||||
"summary": summary,
|
||||
"contains_include_keyword": contains_include_keyword,
|
||||
"contains_exclude_keyword": contains_exclude_keyword
|
||||
}
|
||||
))
|
||||
return results
|
||||
|
||||
# 如果是GET请求或可能返回列表的请求,才进行检查
|
||||
if method not in ['get', 'post']:
|
||||
results.append(self.passed(
|
||||
message=f"跳过检查:{method.upper()} 方法,不适用于分页参数检查"
|
||||
))
|
||||
return results
|
||||
|
||||
# 初始化检查结果
|
||||
found_page_no = False
|
||||
|
||||
Reference in New Issue
Block a user