mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-10 10:19:38 +08:00
fix: json schema validation for testcase v2
This commit is contained in:
@@ -281,19 +281,21 @@ def load_testsuite(raw_testsuite):
|
||||
}
|
||||
|
||||
"""
|
||||
raw_testcases = raw_testsuite.pop("testcases")
|
||||
raw_testsuite["testcases"] = {}
|
||||
raw_testcases = raw_testsuite["testcases"]
|
||||
|
||||
if isinstance(raw_testcases, dict):
|
||||
# make compatible with version < 2.2.0
|
||||
# format version 1, make compatible with version < 2.2.0
|
||||
JsonSchemaChecker.validate_testsuite_v1_format(raw_testsuite)
|
||||
raw_testsuite["testcases"] = {}
|
||||
for name, raw_testcase in raw_testcases.items():
|
||||
__extend_with_testcase_ref(raw_testcase)
|
||||
raw_testcase.setdefault("name", name)
|
||||
raw_testsuite["testcases"][name] = raw_testcase
|
||||
|
||||
elif isinstance(raw_testcases, list):
|
||||
JsonSchemaChecker.validate_testsuite_v2_format(raw_testsuite)
|
||||
# format version 2, implemented in 2.2.0
|
||||
JsonSchemaChecker.validate_testsuite_v2_format(raw_testsuite)
|
||||
raw_testsuite["testcases"] = {}
|
||||
for raw_testcase in raw_testcases:
|
||||
__extend_with_testcase_ref(raw_testcase)
|
||||
testcase_name = raw_testcase["name"]
|
||||
|
||||
@@ -57,6 +57,12 @@ class JsonSchemaChecker(object):
|
||||
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def validate_testsuite_v1_format(content):
|
||||
""" check testsuite format v1 if valid
|
||||
"""
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def validate_testsuite_v2_format(content):
|
||||
""" check testsuite format v2 if valid
|
||||
|
||||
@@ -175,13 +175,32 @@
|
||||
},
|
||||
"extract": {
|
||||
"description": "used to extract session variables for later requests",
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[A-Za-z_][A-Za-z0-9_]*$": {
|
||||
"description": "extraction rule for session variable, maybe in jsonpath/regex/jmespath",
|
||||
"type": "string"
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[A-Za-z_][A-Za-z0-9_]*$": {
|
||||
"description": "extraction rule for session variable, maybe in jsonpath/regex/jmespath",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"minProperties": 1
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"patternProperties": {
|
||||
"^[A-Za-z_][A-Za-z0-9_]*$": {
|
||||
"description": "extraction rule for session variable, maybe in jsonpath/regex/jmespath",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"minProperties": 1,
|
||||
"maxProperties": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"validate": {
|
||||
"description": "used to validate response fields",
|
||||
|
||||
@@ -6,42 +6,13 @@
|
||||
"teststep": {
|
||||
"type": "object",
|
||||
"oneOf": [
|
||||
{
|
||||
"properties": {
|
||||
"name": {
|
||||
"$ref": "common.schema.json#/definitions/name"
|
||||
},
|
||||
"api": {
|
||||
"description": "api reference, value is api file relative path",
|
||||
"type": "string"
|
||||
},
|
||||
"variables": {
|
||||
"$ref": "common.schema.json#/definitions/variables"
|
||||
},
|
||||
"extract": {
|
||||
"$ref": "common.schema.json#/definitions/extract"
|
||||
},
|
||||
"validate": {
|
||||
"$ref": "common.schema.json#/definitions/validate"
|
||||
},
|
||||
"setup_hooks": {
|
||||
"$ref": "common.schema.json#/definitions/hook"
|
||||
},
|
||||
"teardown_hooks": {
|
||||
"$ref": "common.schema.json#/definitions/hook"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"api"
|
||||
]
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"name": {
|
||||
"$ref": "common.schema.json#/definitions/name"
|
||||
},
|
||||
"request": {
|
||||
"description": "define api request directly",
|
||||
"$ref": "common.schema.json#/definitions/request"
|
||||
},
|
||||
"variables": {
|
||||
@@ -64,6 +35,76 @@
|
||||
"name",
|
||||
"request"
|
||||
]
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"name": {
|
||||
"$ref": "common.schema.json#/definitions/name"
|
||||
},
|
||||
"api": {
|
||||
"description": "api reference, value is api file relative path",
|
||||
"type": "string"
|
||||
},
|
||||
"variables": {
|
||||
"$ref": "common.schema.json#/definitions/variables"
|
||||
},
|
||||
"extract": {
|
||||
"oneOf": [
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"$ref": "common.schema.json#/definitions/extract"
|
||||
}
|
||||
]
|
||||
},
|
||||
"validate": {
|
||||
"$ref": "common.schema.json#/definitions/validate"
|
||||
},
|
||||
"setup_hooks": {
|
||||
"$ref": "common.schema.json#/definitions/hook"
|
||||
},
|
||||
"teardown_hooks": {
|
||||
"$ref": "common.schema.json#/definitions/hook"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"api"
|
||||
]
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"name": {
|
||||
"$ref": "common.schema.json#/definitions/name"
|
||||
},
|
||||
"testcase": {
|
||||
"description": "testcase reference, value is testcase file relative path",
|
||||
"type": "string"
|
||||
},
|
||||
"variables": {
|
||||
"$ref": "common.schema.json#/definitions/variables"
|
||||
},
|
||||
"extract": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"setup_hooks": {
|
||||
"$ref": "common.schema.json#/definitions/hook"
|
||||
},
|
||||
"teardown_hooks": {
|
||||
"$ref": "common.schema.json#/definitions/hook"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"name",
|
||||
"testcase"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user