TestRunner orchestrates test execution: - Executor: sends HTTP requests - Extractor: extracts data from responses - Validator: checks assertions - Returns TestResult with pass/fail status
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from .itm import TestModel
|
|
from .context import Context
|
|
from .executor import Executor, Response
|
|
from .extractor import Extractor
|
|
from .validator import Validator
|
|
|
|
|
|
class StepResult:
|
|
def __init__(self, name: str, passed: bool, response: Response):
|
|
self.name = name
|
|
self.passed = passed
|
|
self.response = response
|
|
|
|
|
|
class TestResult:
|
|
def __init__(self, steps: list[StepResult]):
|
|
self.steps = steps
|
|
|
|
@property
|
|
def passed(self) -> bool:
|
|
return all(s.passed for s in self.steps)
|
|
|
|
|
|
class TestRunner:
|
|
def __init__(self, context: Context):
|
|
self.context = context
|
|
self.executor = Executor(context)
|
|
self.extractor = Extractor(context)
|
|
self.validator = Validator()
|
|
|
|
def run(self) -> TestResult:
|
|
results = []
|
|
for step in self.context.config.steps:
|
|
response = self.executor.execute(step.request)
|
|
self.extractor.extract(step.extract, response)
|
|
passed = self.validator.validate(step.assert_, response)
|
|
results.append(StepResult(step.name, passed, response))
|
|
return TestResult(results)
|