refactor: validate with builtin assert methods

This commit is contained in:
debugtalk
2020-04-21 14:54:28 +08:00
parent 1ffe851727
commit 43c4c6590b
2 changed files with 4 additions and 23 deletions

View File

@@ -4,10 +4,10 @@ import jmespath
import requests
from loguru import logger
from httprunner.v3.exceptions import ParamsError, ValidationFailure
from httprunner.v3.parser import parse_data, parse_string_value
from httprunner.v3.exceptions import ValidationFailure
from httprunner.v3.parser import parse_data, parse_string_value, get_mapping_function
from httprunner.v3.schema import VariablesMapping, Validators, FunctionsMapping
from httprunner.v3.validator import uniform_validator, AssertMethods
from httprunner.v3.validator import uniform_validator
class ResponseObject(object):
@@ -39,11 +39,7 @@ class ResponseObject(object):
msg = f"assert {field} {assert_method} {expect_value}"
try:
assert_func = getattr(AssertMethods, assert_method)
except AttributeError:
raise ParamsError(f"Assert Method not supported: {assert_method}")
assert_func = get_mapping_function(assert_method, functions_mapping)
actual_value = parse_string_value(actual_value)
# parse expected value with config/teststep/extracted variables
expect_value = parse_data(expect_value, variables_mapping, functions_mapping)

View File

@@ -89,18 +89,3 @@ def uniform_validator(validator):
"expect": expect_value,
"assert": assert_method
}
class AssertMethods(object):
@staticmethod
def equals(actual_value, expect_value):
assert actual_value == expect_value
@staticmethod
def less_than(actual_value, expect_value):
assert actual_value < expect_value
@staticmethod
def greater_than(actual_value, expect_value):
assert actual_value > expect_value