mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 06:23:52 +08:00
refactor: implement public method JsonSchemaChecker.validate_format
This commit is contained in:
@@ -37,63 +37,46 @@ with open(testsuite_schema_v2_path) as f:
|
|||||||
class JsonSchemaChecker(object):
|
class JsonSchemaChecker(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_api_format(content):
|
def validate_format(content, scheme):
|
||||||
|
""" check api/testcase/testsuite format if valid
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
jsonschema.validate(content, api_schema, resolver=resolver)
|
jsonschema.validate(content, scheme, resolver=resolver)
|
||||||
except jsonschema.exceptions.ValidationError as ex:
|
except jsonschema.exceptions.ValidationError as ex:
|
||||||
logger.log_error(str(ex))
|
logger.log_error(str(ex))
|
||||||
raise exceptions.FileFormatError
|
raise exceptions.FileFormatError
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def validate_api_format(content):
|
||||||
|
""" check api format if valid
|
||||||
|
"""
|
||||||
|
return JsonSchemaChecker.validate_format(content, api_schema)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_testcase_v1_format(content):
|
def validate_testcase_v1_format(content):
|
||||||
""" check testcase format v1 if valid
|
""" check testcase format v1 if valid
|
||||||
"""
|
"""
|
||||||
try:
|
return JsonSchemaChecker.validate_format(content, testcase_schema_v1)
|
||||||
jsonschema.validate(content, testcase_schema_v1, resolver=resolver)
|
|
||||||
except jsonschema.exceptions.ValidationError as ex:
|
|
||||||
logger.log_error(str(ex))
|
|
||||||
raise exceptions.FileFormatError
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
@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
|
||||||
"""
|
"""
|
||||||
try:
|
return JsonSchemaChecker.validate_format(content, testcase_schema_v2)
|
||||||
jsonschema.validate(content, testcase_schema_v2, resolver=resolver)
|
|
||||||
except jsonschema.exceptions.ValidationError as ex:
|
|
||||||
logger.log_error(str(ex))
|
|
||||||
raise exceptions.FileFormatError
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
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:
|
return JsonSchemaChecker.validate_format(content, testsuite_schema_v1)
|
||||||
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
|
@staticmethod
|
||||||
def validate_testsuite_v2_format(content):
|
def validate_testsuite_v2_format(content):
|
||||||
""" check testsuite format v2 if valid
|
""" check testsuite format v2 if valid
|
||||||
"""
|
"""
|
||||||
try:
|
return JsonSchemaChecker.validate_format(content, testsuite_schema_v2)
|
||||||
jsonschema.validate(content, testsuite_schema_v2, resolver=resolver)
|
|
||||||
except jsonschema.exceptions.ValidationError as ex:
|
|
||||||
logger.log_error(str(ex))
|
|
||||||
raise exceptions.FileFormatError
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def is_testcase(data_structure):
|
def is_testcase(data_structure):
|
||||||
|
|||||||
Reference in New Issue
Block a user