mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-07 15:31:23 +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 api
|
||||||
- feat: add json schema validation for testcase v1 & v2
|
- 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**
|
**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")
|
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_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")
|
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")
|
testsuite_schema_v2_path = os.path.join(schemas_root_dir, "testsuite.schema.v2.json")
|
||||||
|
|
||||||
with open(api_schema_path) as f:
|
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:
|
with open(testcase_schema_v2_path) as f:
|
||||||
testcase_schema_v2 = json.load(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:
|
with open(testsuite_schema_v2_path) as f:
|
||||||
testsuite_schema_v2 = json.load(f)
|
testsuite_schema_v2 = json.load(f)
|
||||||
|
|
||||||
@@ -71,6 +75,12 @@ class JsonSchemaChecker(object):
|
|||||||
def validate_testsuite_v1_format(content):
|
def validate_testsuite_v1_format(content):
|
||||||
""" check testsuite format v1 if valid
|
""" 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
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -12,7 +12,19 @@
|
|||||||
},
|
},
|
||||||
"variables": {
|
"variables": {
|
||||||
"description": "define variables for api/teststep/testcase/testsuite",
|
"description": "define variables for api/teststep/testcase/testsuite",
|
||||||
"type": "object"
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "object",
|
||||||
|
"maxProperties": 1,
|
||||||
|
"minProperties": 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"description": "used in testcase/testsuite to configure common fields",
|
"description": "used in testcase/testsuite to configure common fields",
|
||||||
@@ -207,37 +219,34 @@
|
|||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
"description": "one validator definition",
|
"description": "one validator definition",
|
||||||
"type": "object",
|
"oneOf": [
|
||||||
"propertyNames": {
|
{
|
||||||
"enum": [
|
"type": "object",
|
||||||
"eq", "equals", "==", "is",
|
"properties": {
|
||||||
"lt", "less_than",
|
"check": {
|
||||||
"le", "less_than_or_equals",
|
"type": "string"
|
||||||
"gt", "greater_than",
|
},
|
||||||
"ge", "greater_than_or_equals",
|
"comparator": {
|
||||||
"ne", "not_equals",
|
"type": "string"
|
||||||
"str_eq", "string_equals",
|
},
|
||||||
"len_eq", "length_equals", "count_eq",
|
"expect": {
|
||||||
"len_gt", "count_gt", "length_greater_than", "count_greater_than",
|
"description": "expected value"
|
||||||
"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",
|
"required": ["check", "expect"]
|
||||||
"contains",
|
},
|
||||||
"contained_by",
|
{
|
||||||
"type_match",
|
"type": "object",
|
||||||
"regex_match",
|
"patternProperties": {
|
||||||
"startswith",
|
"^[A-Za-z_][A-Za-z0-9_]*$": {
|
||||||
"endswith"
|
"description": "validate_func_name: [check_value, expect_value]",
|
||||||
]
|
"type": "array",
|
||||||
},
|
"minItems": 2,
|
||||||
"patternProperties": {
|
"maxItems": 2
|
||||||
"^[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