MCPcopy
hub / github.com/httprunner/httprunner / validate

Method validate

httprunner/response.py:167–254  ·  view source on GitHub ↗
(
        self,
        validators: Validators,
        variables_mapping: VariablesMapping = None,
    )

Source from the content-addressed store, hash-verified

165 return check_value
166
167 def validate(
168 self,
169 validators: Validators,
170 variables_mapping: VariablesMapping = None,
171 ):
172
173 variables_mapping = variables_mapping or {}
174
175 self.validation_results = {}
176 if not validators:
177 return
178
179 validate_pass = True
180 failures = []
181
182 for v in validators:
183
184 if "validate_extractor" not in self.validation_results:
185 self.validation_results["validate_extractor"] = []
186
187 u_validator = uniform_validator(v)
188
189 # check item
190 check_item = u_validator["check"]
191 if "$" in check_item:
192 # check_item is variable or function
193 check_item = self.parser.parse_data(check_item, variables_mapping)
194 check_item = parse_string_value(check_item)
195
196 if check_item and isinstance(check_item, Text):
197 check_value = self._search_jmespath(check_item)
198 else:
199 # variable or function evaluation result is "" or not text
200 check_value = check_item
201
202 # comparator
203 assert_method = u_validator["assert"]
204 assert_func = self.parser.get_mapping_function(assert_method)
205
206 # expect item
207 expect_item = u_validator["expect"]
208 # parse expected value with config/teststep/extracted variables
209 expect_value = self.parser.parse_data(expect_item, variables_mapping)
210
211 # message
212 message = u_validator["message"]
213 # parse message with config/teststep/extracted variables
214 message = self.parser.parse_data(message, variables_mapping)
215
216 validate_msg = f"assert {check_item} {assert_method} {expect_value}({type(expect_value).__name__})"
217
218 validator_dict = {
219 "comparator": assert_method,
220 "check": check_item,
221 "check_value": check_value,
222 "expect": expect_item,
223 "expect_value": expect_value,
224 "message": message,

Callers 15

test_validateMethod · 0.45
TestCaseDemoSqliteClass · 0.45
TestCaseT23Class · 0.45
TestCaseT1Class · 0.45
TestCaseValidateClass · 0.45
TestCaseUploadClass · 0.45
TestCaseHooksClass · 0.45
TestCaseBasicClass · 0.45

Calls 6

_search_jmespathMethod · 0.95
parse_string_valueFunction · 0.90
ValidationFailureClass · 0.90
uniform_validatorFunction · 0.85
parse_dataMethod · 0.80
get_mapping_functionMethod · 0.80

Tested by 3

test_validateMethod · 0.36