mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-12 02:21:29 +08:00
refactor: validate with builtin assert methods
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user