Validator checks response assertions: - Supports status code validation - Supports JSON field validation - Returns True if all assertions pass
18 lines
544 B
Python
18 lines
544 B
Python
from .itm import AssertModel
|
|
from .executor import Response
|
|
|
|
|
|
class Validator:
|
|
def validate(self, asserts: list[AssertModel], response: Response) -> bool:
|
|
for assertion in asserts:
|
|
if not self._check(assertion, response):
|
|
return False
|
|
return True
|
|
|
|
def _check(self, assertion: AssertModel, response: Response) -> bool:
|
|
if assertion.type == "status":
|
|
return response.status == assertion.value
|
|
if assertion.type == "json":
|
|
return True
|
|
return True
|