fix #255: validate with custom functions

This commit is contained in:
httprunner
2018-06-11 21:52:21 +08:00
parent a202fc0866
commit 28ae4d0c97
4 changed files with 22 additions and 9 deletions

View File

@@ -1,7 +1,7 @@
__title__ = 'HttpRunner'
__description__ = 'One-stop solution for HTTP(S) testing.'
__url__ = 'https://github.com/HttpRunner/HttpRunner'
__version__ = '1.4.6'
__version__ = '1.4.7'
__author__ = 'debugtalk'
__author_email__ = 'mail@debugtalk.com'
__license__ = 'MIT'

View File

@@ -188,17 +188,21 @@ class Context(object):
}
"""
check_item = validator["check"]
# check_item should only be in 4 types:
# check_item should only be the following 5 formats:
# 1, variable reference, e.g. $token
# 2, string joined by delimiter. e.g. "status_code", "headers.content-type"
# 3, regex string, e.g. "LB[\d]*(.*)RB[\d]*"
# 4, dict or list, maybe containing variables reference, e.g. {"var": "$abc"}
if isinstance(check_item, (dict, list)) or testcase.extract_variables(check_item):
# type 4 or type 1
# 2, function reference, e.g. ${is_status_code_200($status_code)}
# 3, dict or list, maybe containing variable/function reference, e.g. {"var": "$abc"}
# 4, string joined by delimiter. e.g. "status_code", "headers.content-type"
# 5, regex string, e.g. "LB[\d]*(.*)RB[\d]*"
if isinstance(check_item, (dict, list)) \
or testcase.extract_variables(check_item) \
or testcase.extract_functions(check_item):
# format 1/2/3
check_value = self.eval_content(check_item)
else:
try:
# type 2 or type 3
# format 4/5
check_value = resp_obj.extract_field(check_item)
except exception.ParseResponseError:
msg = "failed to extract check item from response!\n"