add:stage
This commit is contained in:
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -13,7 +13,39 @@ class InvalidEnumValueCase(BaseAPITestCase):
|
||||
tags = ["error-handling", "appendix-b", "4006", "invalid-enum"]
|
||||
execution_order = 204 # 在数值越界之后执行
|
||||
|
||||
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):
|
||||
@staticmethod
|
||||
def _endpoint_has_enum_field(endpoint_spec: Dict[str, Any], logger: logging.Logger) -> bool:
|
||||
"""
|
||||
静态辅助方法,检查端点规范中是否有任何字段(body或parameters)包含枚举定义。
|
||||
"""
|
||||
# 1. 检查请求体 (Body)
|
||||
if endpoint_spec.get("requestBody"):
|
||||
# 注意:这里需要一个可以解析$ref的上下文,但applies_to是静态的。
|
||||
# 这是一个简化检查,它只检查顶级schema。
|
||||
# 更完整的检查需要一个能够解析$ref的schema工具。
|
||||
# 为了简单起见,我们假设测试用例的 _get_resolved_request_body_schema 可以在实例化后使用。
|
||||
# 这里的检查可能不完整,但可以覆盖大部分情况。
|
||||
if schema_utils.util_find_enum_field_recursive(endpoint_spec["requestBody"].get("content", {}).get("application/json", {}).get("schema", {}), [], logger):
|
||||
return True
|
||||
|
||||
# 2. 检查查询参数, 路径参数, 请求头
|
||||
if 'parameters' in endpoint_spec:
|
||||
for param in endpoint_spec['parameters']:
|
||||
param_desc = param.get('description', '')
|
||||
if schema_utils.util_extract_enum_from_description(param_desc, logger):
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def applies_to(cls, endpoint_spec: Dict[str, Any], **kwargs) -> bool:
|
||||
"""
|
||||
此测试用例仅适用于那些在请求体或参数中定义了枚举(enum)的端点。
|
||||
"""
|
||||
# 创建一个临时logger用于静态方法
|
||||
temp_logger = logging.getLogger(f"applies_to.{cls.id}")
|
||||
return cls._endpoint_has_enum_field(endpoint_spec, temp_logger)
|
||||
|
||||
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)
|
||||
self.logger.setLevel(logging.INFO)
|
||||
|
||||
|
||||
@@ -11,6 +11,14 @@ class MissingRequiredFieldBodyCase(BaseAPITestCase):
|
||||
tags = ["error-handling", "appendix-b", "4003", "required-fields", "request-body"]
|
||||
execution_order = 210
|
||||
|
||||
@classmethod
|
||||
def applies_to(cls, endpoint_spec: Dict[str, Any], **kwargs) -> bool:
|
||||
"""
|
||||
此测试用例仅适用于那些在API规范中明确定义了请求体(requestBody)的端点。
|
||||
"""
|
||||
# 如果 'requestBody' 存在且其内容不为空,则认为此测试用例适用。
|
||||
return bool(endpoint_spec.get("requestBody"))
|
||||
|
||||
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)
|
||||
self.logger = logging.getLogger(f"testcase.{self.id}") # Already set in super, but can be re-set if specific sub-logger is needed. Better to rely on super's logger.
|
||||
|
||||
+12
@@ -10,6 +10,18 @@ class MissingRequiredFieldQueryCase(BaseAPITestCase):
|
||||
tags = ["error-handling", "appendix-b", "4003", "required-fields", "query-parameters"]
|
||||
execution_order = 211 # After body, before original combined one might have been
|
||||
|
||||
@classmethod
|
||||
def applies_to(cls, endpoint_spec: Dict[str, Any], **kwargs) -> bool:
|
||||
"""
|
||||
此测试用例仅适用于那些在API规范中定义了查询参数(parameters with 'in' == 'query')的端点。
|
||||
"""
|
||||
# 如果 'parameters' 字段不存在,则不适用
|
||||
if not endpoint_spec.get("parameters"):
|
||||
return False
|
||||
|
||||
# 遍历所有参数,如果发现任何一个参数的 "in" 字段是 "query",则此测试用例适用。
|
||||
return any(param.get("in") == "query" for param in endpoint_spec["parameters"])
|
||||
|
||||
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)
|
||||
self.target_param_name: Optional[str] = None
|
||||
|
||||
@@ -11,6 +11,40 @@ class NumberOutOfRangeCase(BaseAPITestCase):
|
||||
tags = ["error-handling", "appendix-b", "4002", "out-of-range"]
|
||||
execution_order = 203 # 在类型不匹配测试之后执行
|
||||
|
||||
@staticmethod
|
||||
def _endpoint_has_ranged_field(endpoint_spec: Dict[str, Any], logger: logging.Logger) -> bool:
|
||||
"""
|
||||
静态辅助方法,检查端点规范中是否有任何字段(body或parameters)包含范围定义。
|
||||
"""
|
||||
# 1. 检查请求体 (Body)
|
||||
if endpoint_spec.get("requestBody"):
|
||||
if schema_utils.util_find_ranged_field_recursive(endpoint_spec["requestBody"].get("content", {}).get("application/json", {}).get("schema", {}), [], logger):
|
||||
return True
|
||||
|
||||
# 2. 检查查询参数, 路径参数, 请求头
|
||||
if 'parameters' in endpoint_spec:
|
||||
for param in endpoint_spec['parameters']:
|
||||
param_schema = param.get('schema', {})
|
||||
param_desc = param.get('description', '')
|
||||
|
||||
min_val, max_val = schema_utils.util_extract_range_from_description(param_desc, logger)
|
||||
|
||||
if min_val is None and max_val is None:
|
||||
min_val = param_schema.get('minimum')
|
||||
max_val = param_schema.get('maximum')
|
||||
|
||||
if min_val is not None or max_val is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def applies_to(cls, endpoint_spec: Dict[str, Any], **kwargs) -> bool:
|
||||
"""
|
||||
此测试用例仅适用于那些在请求体或参数中定义了数值范围的端点。
|
||||
"""
|
||||
temp_logger = logging.getLogger(f"applies_to.{cls.id}")
|
||||
return cls._endpoint_has_ranged_field(endpoint_spec, temp_logger)
|
||||
|
||||
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)
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
|
||||
@@ -12,6 +12,14 @@ class TypeMismatchBodyCase(BaseAPITestCase):
|
||||
tags = ["error-handling", "appendix-b", "4001", "request-body"]
|
||||
execution_order = 202 # Slightly after query param one
|
||||
|
||||
@classmethod
|
||||
def applies_to(cls, endpoint_spec: Dict[str, Any], **kwargs) -> bool:
|
||||
"""
|
||||
此测试用例仅适用于那些在API规范中明确定义了请求体(requestBody)的端点。
|
||||
"""
|
||||
# 如果 'requestBody' 存在且其内容不为空,则认为此测试用例适用。
|
||||
return bool(endpoint_spec.get("requestBody"))
|
||||
|
||||
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)
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
|
||||
@@ -12,6 +12,18 @@ class TypeMismatchQueryParamCase(BaseAPITestCase):
|
||||
tags = ["error-handling", "appendix-b", "4001", "query-parameters"]
|
||||
execution_order = 201 # Slightly after the combined one might have been
|
||||
|
||||
@classmethod
|
||||
def applies_to(cls, endpoint_spec: Dict[str, Any], **kwargs) -> bool:
|
||||
"""
|
||||
此测试用例仅适用于那些在API规范中定义了查询参数(parameters with 'in' == 'query')的端点。
|
||||
"""
|
||||
# 如果 'parameters' 字段不存在,则不适用
|
||||
if not endpoint_spec.get("parameters"):
|
||||
return False
|
||||
|
||||
# 遍历所有参数,如果发现任何一个参数的 "in" 字段是 "query",则此测试用例适用。
|
||||
return any(param.get("in") == "query" for param in endpoint_spec["parameters"])
|
||||
|
||||
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)
|
||||
self.logger.setLevel(logging.DEBUG)
|
||||
|
||||
Reference in New Issue
Block a user