From 456e966570c55dcc4052a0244b9c0c69ba8910d3 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Thu, 9 Apr 2020 11:08:59 +0800 Subject: [PATCH] change: remove compatibility with testsuite format v1 --- docs/CHANGELOG.md | 2 +- httprunner/loader/buildup.py | 45 +++---------- httprunner/loader/check.py | 16 ----- .../loader/schemas/testsuite.schema.v1.json | 66 ------------------- 4 files changed, 10 insertions(+), 119 deletions(-) delete mode 100644 httprunner/loader/schemas/testsuite.schema.v1.json diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 20dfa5d9..1daf3c66 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,7 +4,7 @@ **Changed** -- remove compatibility with testcase format v1 +- remove compatibility with testcase/testsuite format v1 ## 3.0.1 (2020-03-24) diff --git a/httprunner/loader/buildup.py b/httprunner/loader/buildup.py index 55f36287..b18b6eaf 100644 --- a/httprunner/loader/buildup.py +++ b/httprunner/loader/buildup.py @@ -189,23 +189,6 @@ def load_testsuite(raw_testsuite): Args: raw_testsuite (dict): raw testsuite content loaded from JSON/YAML file: - # version 1, compatible with version < 2.2.0 - { - "config": { - "name": "xxx", - "variables": {} - } - "testcases": { - "testcase1": { - "testcase": "/path/to/testcase", - "variables": {...}, - "parameters": {...} - }, - "testcase2": {} - } - } - - # version 2, implemented in 2.2.0 { "config": { "name": "xxx", @@ -232,28 +215,18 @@ def load_testsuite(raw_testsuite): """ raw_testcases = raw_testsuite["testcases"] - if isinstance(raw_testcases, dict): - # 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): - # 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"] - raw_testsuite["testcases"][testcase_name] = raw_testcase - - else: + # TODO: validate with pydantic + if not isinstance(raw_testcases, list): # invalid format raise exceptions.FileFormatError("Invalid testsuite format!") + 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"] + raw_testsuite["testcases"][testcase_name] = raw_testcase + return raw_testsuite diff --git a/httprunner/loader/check.py b/httprunner/loader/check.py index 63d7149b..29730e3a 100644 --- a/httprunner/loader/check.py +++ b/httprunner/loader/check.py @@ -12,7 +12,6 @@ schemas_root_dir = os.path.join(os.path.dirname(__file__), "schemas") 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_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 io.open(api_schema_path, encoding='utf-8') as f: @@ -31,9 +30,6 @@ with io.open(common_schema_path, encoding='utf-8') as f: with io.open(testcase_schema_v2_path, encoding='utf-8') as f: testcase_schema_v2 = json.load(f) -with io.open(testsuite_schema_v1_path, encoding='utf-8') as f: - testsuite_schema_v1 = json.load(f) - with io.open(testsuite_schema_v2_path, encoding='utf-8') as f: testsuite_schema_v2 = json.load(f) @@ -64,12 +60,6 @@ class JsonSchemaChecker(object): """ return JsonSchemaChecker.validate_format(content, testcase_schema_v2) - @staticmethod - def validate_testsuite_v1_format(content): - """ check testsuite format v1 if valid - """ - return JsonSchemaChecker.validate_format(content, testsuite_schema_v1) - @staticmethod def validate_testsuite_v2_format(content): """ check testsuite format v2 if valid @@ -178,12 +168,6 @@ def is_test_content(data_structure): for item in testsuites: is_testcase = False - try: - JsonSchemaChecker.validate_testsuite_v1_format(item) - is_testcase = True - except exceptions.FileFormatError: - pass - try: JsonSchemaChecker.validate_testsuite_v2_format(item) is_testcase = True diff --git a/httprunner/loader/schemas/testsuite.schema.v1.json b/httprunner/loader/schemas/testsuite.schema.v1.json deleted file mode 100644 index 85a8a72a..00000000 --- a/httprunner/loader/schemas/testsuite.schema.v1.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "$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": "testcase 1", - "testcase": "/path/to/testcase1" - }, - "testcase 2": { - "name": "testcase 2", - "testcase": "/path/to/testcase2" - } - } - } - ] -} \ No newline at end of file