Context stores execution state:
- variables: static test variables
- extracted: data extracted from responses
- resolve(): replaces {{var}} placeholders with values
20 lines
598 B
Python
20 lines
598 B
Python
from typing import Any
|
|
from .itm import TestModel
|
|
|
|
|
|
class Context:
|
|
def __init__(self, config: TestModel):
|
|
self.config = config
|
|
self.variables: dict[str, str] = config.variables.copy()
|
|
self.extracted: dict[str, Any] = {}
|
|
|
|
def resolve(self, template: str) -> str:
|
|
result = template
|
|
all_vars = {**self.variables, **self.extracted}
|
|
for key, value in all_vars.items():
|
|
result = result.replace(f"{{{{{key}}}}}", str(value))
|
|
return result
|
|
|
|
def set_extracted(self, name: str, value: Any):
|
|
self.extracted[name] = value
|