mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 23:51:25 +08:00
change: remove compatibility with testcase format v1
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
# Release History
|
# Release History
|
||||||
|
|
||||||
|
## 3.0.2 (2020-04-09)
|
||||||
|
|
||||||
|
**Changed**
|
||||||
|
|
||||||
|
- remove compatibility with testcase format v1
|
||||||
|
|
||||||
## 3.0.1 (2020-03-24)
|
## 3.0.1 (2020-03-24)
|
||||||
|
|
||||||
**Changed**
|
**Changed**
|
||||||
|
|||||||
@@ -78,11 +78,8 @@ def __extend_with_testcase_ref(raw_testinfo):
|
|||||||
)
|
)
|
||||||
loaded_testcase = load_file(testcase_path)
|
loaded_testcase = load_file(testcase_path)
|
||||||
|
|
||||||
if isinstance(loaded_testcase, list):
|
# TODO: validate with pydantic
|
||||||
# make compatible with version < 2.2.0
|
if isinstance(loaded_testcase, dict) and "teststeps" in loaded_testcase:
|
||||||
testcase_dict = load_testcase(loaded_testcase)
|
|
||||||
elif isinstance(loaded_testcase, dict) and "teststeps" in loaded_testcase:
|
|
||||||
# format version 2, implemented in 2.2.0
|
|
||||||
testcase_dict = load_testcase_v2(loaded_testcase)
|
testcase_dict = load_testcase_v2(loaded_testcase)
|
||||||
else:
|
else:
|
||||||
raise exceptions.FileFormatError(
|
raise exceptions.FileFormatError(
|
||||||
@@ -147,57 +144,6 @@ def load_teststep(raw_testinfo):
|
|||||||
return raw_testinfo
|
return raw_testinfo
|
||||||
|
|
||||||
|
|
||||||
def load_testcase(raw_testcase):
|
|
||||||
""" load testcase with api/testcase references.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
raw_testcase (list): raw testcase content loaded from JSON/YAML file:
|
|
||||||
[
|
|
||||||
# config part
|
|
||||||
{
|
|
||||||
"config": {
|
|
||||||
"name": "XXXX",
|
|
||||||
"base_url": "https://debugtalk.com"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
# teststeps part
|
|
||||||
{
|
|
||||||
"test": {...}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"test": {...}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
dict: loaded testcase content
|
|
||||||
{
|
|
||||||
"config": {},
|
|
||||||
"teststeps": [test11, test12]
|
|
||||||
}
|
|
||||||
|
|
||||||
"""
|
|
||||||
JsonSchemaChecker.validate_testcase_v1_format(raw_testcase)
|
|
||||||
config = {}
|
|
||||||
tests = []
|
|
||||||
|
|
||||||
for item in raw_testcase:
|
|
||||||
key, test_block = item.popitem()
|
|
||||||
if key == "config":
|
|
||||||
config.update(test_block)
|
|
||||||
elif key == "test":
|
|
||||||
tests.append(load_teststep(test_block))
|
|
||||||
else:
|
|
||||||
logger.warning(
|
|
||||||
f"unexpected block key: {key}. block key should only be 'config' or 'test'."
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
|
||||||
"config": config,
|
|
||||||
"teststeps": tests
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def load_testcase_v2(raw_testcase):
|
def load_testcase_v2(raw_testcase):
|
||||||
""" load testcase in format version 2.
|
""" load testcase in format version 2.
|
||||||
|
|
||||||
@@ -311,7 +257,7 @@ def load_testsuite(raw_testsuite):
|
|||||||
return raw_testsuite
|
return raw_testsuite
|
||||||
|
|
||||||
|
|
||||||
def load_test_file(path):
|
def load_test_file(path: str) -> dict:
|
||||||
""" load test file, file maybe testcase/testsuite/api
|
""" load test file, file maybe testcase/testsuite/api
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@@ -347,7 +293,9 @@ def load_test_file(path):
|
|||||||
"""
|
"""
|
||||||
raw_content = load_file(path)
|
raw_content = load_file(path)
|
||||||
|
|
||||||
if isinstance(raw_content, dict):
|
if not isinstance(raw_content, dict):
|
||||||
|
# invalid format
|
||||||
|
raise exceptions.FileFormatError("Invalid test file format!")
|
||||||
|
|
||||||
if "testcases" in raw_content:
|
if "testcases" in raw_content:
|
||||||
# file_type: testsuite
|
# file_type: testsuite
|
||||||
@@ -372,17 +320,6 @@ def load_test_file(path):
|
|||||||
# invalid format
|
# invalid format
|
||||||
raise exceptions.FileFormatError("Invalid test file format!")
|
raise exceptions.FileFormatError("Invalid test file format!")
|
||||||
|
|
||||||
elif isinstance(raw_content, list) and len(raw_content) > 0:
|
|
||||||
# file_type: testcase
|
|
||||||
# make compatible with version < 2.2.0
|
|
||||||
loaded_content = load_testcase(raw_content)
|
|
||||||
loaded_content["path"] = path
|
|
||||||
loaded_content["type"] = "testcase"
|
|
||||||
|
|
||||||
else:
|
|
||||||
# invalid format
|
|
||||||
raise exceptions.FileFormatError("Invalid test file format!")
|
|
||||||
|
|
||||||
return loaded_content
|
return loaded_content
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from httprunner import exceptions
|
|||||||
schemas_root_dir = os.path.join(os.path.dirname(__file__), "schemas")
|
schemas_root_dir = os.path.join(os.path.dirname(__file__), "schemas")
|
||||||
common_schema_path = os.path.join(schemas_root_dir, "common.schema.json")
|
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_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_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")
|
||||||
@@ -29,9 +28,6 @@ with io.open(common_schema_path, encoding='utf-8') as f:
|
|||||||
common_schema = json.load(f)
|
common_schema = json.load(f)
|
||||||
resolver = jsonschema.RefResolver(absolute_base_path, common_schema)
|
resolver = jsonschema.RefResolver(absolute_base_path, common_schema)
|
||||||
|
|
||||||
with io.open(testcase_schema_v1_path, encoding='utf-8') as f:
|
|
||||||
testcase_schema_v1 = json.load(f)
|
|
||||||
|
|
||||||
with io.open(testcase_schema_v2_path, encoding='utf-8') as f:
|
with io.open(testcase_schema_v2_path, encoding='utf-8') as f:
|
||||||
testcase_schema_v2 = json.load(f)
|
testcase_schema_v2 = json.load(f)
|
||||||
|
|
||||||
@@ -62,12 +58,6 @@ class JsonSchemaChecker(object):
|
|||||||
"""
|
"""
|
||||||
return JsonSchemaChecker.validate_format(content, api_schema)
|
return JsonSchemaChecker.validate_format(content, api_schema)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def validate_testcase_v1_format(content):
|
|
||||||
""" check testcase format v1 if valid
|
|
||||||
"""
|
|
||||||
return JsonSchemaChecker.validate_format(content, testcase_schema_v1)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_testcase_v2_format(content):
|
def validate_testcase_v2_format(content):
|
||||||
""" check testcase format v2 if valid
|
""" check testcase format v2 if valid
|
||||||
@@ -175,12 +165,6 @@ def is_test_content(data_structure):
|
|||||||
except exceptions.FileFormatError:
|
except exceptions.FileFormatError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
|
||||||
JsonSchemaChecker.validate_testcase_v2_format(item)
|
|
||||||
is_testcase = True
|
|
||||||
except exceptions.FileFormatError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if not is_testcase:
|
if not is_testcase:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
{
|
|
||||||
"$schema": "http://json-schema.org/draft-07/schema",
|
|
||||||
"description": "httprunner testcase schema v1 definition",
|
|
||||||
"type": "array",
|
|
||||||
"definitions": {
|
|
||||||
"test": {
|
|
||||||
"type": "object",
|
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"properties": {
|
|
||||||
"name": {
|
|
||||||
"$ref": "common.schema.json#/definitions/name"
|
|
||||||
},
|
|
||||||
"request": {
|
|
||||||
"description": "define api request directly",
|
|
||||||
"$ref": "common.schema.json#/definitions/request"
|
|
||||||
},
|
|
||||||
"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",
|
|
||||||
"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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"items": {
|
|
||||||
"type": "object",
|
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"config": {
|
|
||||||
"$ref": "common.schema.json#/definitions/config"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"test": {
|
|
||||||
"$ref": "testcase.schema.v1.json#/definitions/test"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"additionalProperties": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"minProperties": 1,
|
|
||||||
"maxProperties": 1
|
|
||||||
},
|
|
||||||
"minItems": 2
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user