mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
feat: add json schema validation for testsutie v1
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
- feat: add json schema validation for api
|
||||
- feat: add json schema validation for testcase v1 & v2
|
||||
- feat: add json schema validation for testsuite v2
|
||||
- feat: add json schema validation for testsuite v1 & v2
|
||||
|
||||
**Changed**
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ common_schema_path = os.path.join(schemas_root_dir, "common.schema.json")
|
||||
api_schema_path = os.path.join(schemas_root_dir, "api.schema.json")
|
||||
testcase_schema_v1_path = os.path.join(schemas_root_dir, "testcase.schema.v1.json")
|
||||
testcase_schema_v2_path = os.path.join(schemas_root_dir, "testcase.schema.v2.json")
|
||||
testsuite_schema_v1_path = os.path.join(schemas_root_dir, "testsuite.schema.v1.json")
|
||||
testsuite_schema_v2_path = os.path.join(schemas_root_dir, "testsuite.schema.v2.json")
|
||||
|
||||
with open(api_schema_path) as f:
|
||||
@@ -26,6 +27,9 @@ with open(testcase_schema_v1_path) as f:
|
||||
with open(testcase_schema_v2_path) as f:
|
||||
testcase_schema_v2 = json.load(f)
|
||||
|
||||
with open(testsuite_schema_v1_path) as f:
|
||||
testsuite_schema_v1 = json.load(f)
|
||||
|
||||
with open(testsuite_schema_v2_path) as f:
|
||||
testsuite_schema_v2 = json.load(f)
|
||||
|
||||
@@ -71,6 +75,12 @@ class JsonSchemaChecker(object):
|
||||
def validate_testsuite_v1_format(content):
|
||||
""" check testsuite format v1 if valid
|
||||
"""
|
||||
try:
|
||||
jsonschema.validate(content, testsuite_schema_v1, resolver=resolver)
|
||||
except jsonschema.exceptions.ValidationError as ex:
|
||||
logger.log_error(str(ex))
|
||||
raise exceptions.FileFormatError
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -12,7 +12,19 @@
|
||||
},
|
||||
"variables": {
|
||||
"description": "define variables for api/teststep/testcase/testsuite",
|
||||
"type": "object"
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"maxProperties": 1,
|
||||
"minProperties": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"config": {
|
||||
"description": "used in testcase/testsuite to configure common fields",
|
||||
@@ -207,37 +219,34 @@
|
||||
"type": "array",
|
||||
"items": {
|
||||
"description": "one validator definition",
|
||||
"type": "object",
|
||||
"propertyNames": {
|
||||
"enum": [
|
||||
"eq", "equals", "==", "is",
|
||||
"lt", "less_than",
|
||||
"le", "less_than_or_equals",
|
||||
"gt", "greater_than",
|
||||
"ge", "greater_than_or_equals",
|
||||
"ne", "not_equals",
|
||||
"str_eq", "string_equals",
|
||||
"len_eq", "length_equals", "count_eq",
|
||||
"len_gt", "count_gt", "length_greater_than", "count_greater_than",
|
||||
"len_ge", "count_ge", "length_greater_than_or_equals", "count_greater_than_or_equals",
|
||||
"len_lt", "count_lt", "length_less_than", "count_less_than",
|
||||
"len_le", "count_le", "length_less_than_or_equals", "count_less_than_or_equals",
|
||||
"contains",
|
||||
"contained_by",
|
||||
"type_match",
|
||||
"regex_match",
|
||||
"startswith",
|
||||
"endswith"
|
||||
]
|
||||
},
|
||||
"patternProperties": {
|
||||
"^[A-Za-z_][A-Za-z0-9_]*$": {
|
||||
"description": "validate_func_name: [check_value, expect_value]",
|
||||
"type": "array",
|
||||
"minItems": 2,
|
||||
"maxItems": 2
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"check": {
|
||||
"type": "string"
|
||||
},
|
||||
"comparator": {
|
||||
"type": "string"
|
||||
},
|
||||
"expect": {
|
||||
"description": "expected value"
|
||||
}
|
||||
},
|
||||
"required": ["check", "expect"]
|
||||
},
|
||||
{
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[A-Za-z_][A-Za-z0-9_]*$": {
|
||||
"description": "validate_func_name: [check_value, expect_value]",
|
||||
"type": "array",
|
||||
"minItems": 2,
|
||||
"maxItems": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
66
httprunner/loader/schemas/testsuite.schema.v1.json
Normal file
66
httprunner/loader/schemas/testsuite.schema.v1.json
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema",
|
||||
"description": "httprunner testsuite schema v1 definition",
|
||||
"type": "object",
|
||||
"definitions": {
|
||||
"testcase": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"$ref": "common.schema.json#/definitions/name"
|
||||
},
|
||||
"variables": {
|
||||
"$ref": "common.schema.json#/definitions/variables"
|
||||
},
|
||||
"parameters": {
|
||||
"description": "generate cartesian product variables with parameters, each group of variables will be run once",
|
||||
"type": "object"
|
||||
},
|
||||
"testcase": {
|
||||
"description": "testcase reference, value is testcase file relative path",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"testcase"
|
||||
]
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"config": {
|
||||
"$ref": "common.schema.json#/definitions/config"
|
||||
},
|
||||
"testcases": {
|
||||
"description": "testcase of a testsuite",
|
||||
"type": "object",
|
||||
"minProperties": 1,
|
||||
"patternProperties": {
|
||||
".*": {
|
||||
"description": "testcase definition",
|
||||
"$ref": "testsuite.schema.v1.json#/definitions/testcase"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"config",
|
||||
"testcases"
|
||||
],
|
||||
"examples": [
|
||||
{
|
||||
"config": {
|
||||
"name": "testsuite name"
|
||||
},
|
||||
"testcases": {
|
||||
"testcase 1": {
|
||||
"name": "xxx",
|
||||
"testcase": "/path/to/testcase1"
|
||||
},
|
||||
"testcase 2": {
|
||||
"name": "xxx",
|
||||
"testcase": "/path/to/testcase2"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user