This commit is contained in:
gongwenxin
2025-07-19 08:44:40 +08:00
parent 9a4afa8238
commit fcdfe71646
152 changed files with 598342 additions and 73747 deletions
+22 -12
View File
@@ -24,10 +24,14 @@ class TestDataGenerationConfig(BaseModel):
schema_source: Optional[str] = Field(default=None, description="Identifier for the schema to be used (e.g., operationId, or path to schema file).")
# For FROM_PREVIOUS_STEP strategy:
source_step_id: Optional[str] = Field(default=None, description="The ID of the previous TestStep whose output will be used.")
extraction_rules: Optional[Dict[str, str]] = Field(default_None, description="Rules to extract data (e.g., JSONPath expressions like {'user_id': '$.body.id'}).")
extraction_rules: Optional[Dict[str, str]] = Field(default=None, description="Rules to extract data (e.g., JSONPath expressions like {'user_id': '$.body.id'}).")
# For AI_GENERATED strategy:
ai_prompt: Optional[str] = Field(default=None, description="Prompt to be used by an AI model to generate data.")
ai_model_config: Optional[Dict[str, Any]] = Field(default_None, description="Configuration for the AI model (e.g., temperature, max_tokens).")
ai_model_config: Optional[Dict[str, Any]] = Field(default=None, description="Configuration for the AI model (e.g., temperature, max_tokens).")
use_llm_for_body: bool = Field(False, description="Whether to use LLM to generate request bodies.")
use_llm_for_path_params: bool = Field(False, description="Whether to use LLM to generate path parameters.")
use_llm_for_query_params: bool = Field(False, description="Whether to use LLM to generate query parameters.")
use_llm_for_headers: bool = Field(False, description="Whether to use LLM to generate headers.")
class APIRequestContext(BaseModel):
"""
@@ -36,10 +40,10 @@ class APIRequestContext(BaseModel):
"""
method: str = Field(description="HTTP method (GET, POST, PUT, DELETE, etc.).")
url_template: str = Field(description="URL template, can contain placeholders like {base_url} or {resource_id}.")
path_params_source: Optional[Dict[str, TestDataGenerationConfig]] = Field(default_None, description="How to generate/get path parameters.")
query_params_source: Optional[Dict[str, TestDataGenerationConfig]] = Field(default_None, description="How to generate/get query parameters.")
headers_source: Optional[Dict[str, TestDataGenerationConfig]] = Field(default_None, description="How to generate/get request headers. Default headers can be added by the orchestrator.")
body_source: Optional[TestDataGenerationConfig] = Field(default_None, description="How to generate/get the request body.")
path_params_source: Optional[Dict[str, TestDataGenerationConfig]] = Field(default=None, description="How to generate/get path parameters.")
query_params_source: Optional[Dict[str, TestDataGenerationConfig]] = Field(default=None, description="How to generate/get query parameters.")
headers_source: Optional[Dict[str, TestDataGenerationConfig]] = Field(default=None, description="How to generate/get request headers. Default headers can be added by the orchestrator.")
body_source: Optional[TestDataGenerationConfig] = Field(default=None, description="How to generate/get the request body.")
# Stores the actual APIRequest object after context resolution
# This field will be populated by the TestOrchestrator before execution.
@@ -70,13 +74,13 @@ class TestStep(BaseModel):
expected_status_code: Optional[int] = Field(default=None, description="Expected HTTP status code.")
# Allows defining assertions on the response body using something like JSONPath
# e.g., {"$.data.status": "completed", "$.errors": null}
response_body_assertions: Optional[Dict[str, Any]] = Field(default_None, description="Assertions to make on the response body (e.g., using JSONPath).")
response_body_assertions: Optional[Dict[str, Any]] = Field(default=None, description="Assertions to make on the response body (e.g., using JSONPath).")
# Execution control
skip: bool = Field(default=False, description="If True, this test step will be skipped.")
# Allows storing output from this step to be used by subsequent steps
# e.g., {"created_user_id": "$.response.body.id"}
outputs_to_extract: Optional[Dict[str, str]] = Field(default_None, description="JSONPath expressions to extract data from response to be used in later steps.")
outputs_to_extract: Optional[Dict[str, str]] = Field(default=None, description="JSONPath expressions to extract data from response to be used in later steps.")
class TestCaseExecutionMode(str, Enum):
@@ -130,15 +134,21 @@ class TestSuite(BaseModel):
# Global parameters or configurations that can apply to all TestCases in the suite
# These could override individual TestCase settings or provide defaults.
global_parameters: Optional[Dict[str, Any]] = Field(default_None, description="Parameters applicable to all test cases in the suite.")
global_parameters: Optional[Dict[str, Any]] = Field(default=None, description="Parameters applicable to all test cases in the suite.")
# Setup: API calls or actions to perform before running any TestCase in the suite.
# Similar structure to TestStep but without specific rule validations, more for setup.
setup_steps: Optional[List[TestStep]] = Field(default_None, description="Steps to execute before running test cases in the suite.")
setup_steps: Optional[List[TestStep]] = Field(default=None, description="Steps to execute before running test cases in the suite.")
# Teardown: API calls or actions to perform after all TestCases in the suite have run.
teardown_steps: Optional[List[TestStep]] = Field(default_None, description="Steps to execute after running test cases in the suite.")
teardown_steps: Optional[List[TestStep]] = Field(default=None, description="Steps to execute after running test cases in the suite.")
# Execution control for the suite
# e.g., run all, run tagged, run failed from previous
execution_strategy: Optional[str] = Field(default=None, description="Strategy for executing test cases within the suite.")
execution_strategy: Optional[str] = Field(default=None, description="Strategy for executing test cases within the suite.")
class TestRunConfig(BaseModel):
"""
Configuration for running a test run.
"""
# ... existing code ...