refactor: add extract_binds and validators

This commit is contained in:
debugtalk
2017-06-29 15:27:26 +08:00
parent 997e9d642b
commit 6854607cf0
16 changed files with 327 additions and 546 deletions

View File

@@ -8,7 +8,6 @@ class Context(object):
def __init__(self):
self.functions = dict()
self.variables = dict() # Maps variable name to value
self.extractors = dict()
def import_requires(self, modules):
""" import required modules dynamicly
@@ -45,19 +44,10 @@ class Context(object):
for var_name, var_value in variable_bind_map.items():
self.variables[var_name] = self.get_eval_value(var_value)
def bind_extractors(self, extract_binds):
""" Bind named extractors to value within the context.
value => parsed from requests.Response object
key => extractor name, can be used as variable in next testcases
@param (dict) extract_binds
{
"resp_status_code": "status_code",
"resp_headers": "headers",
"resp_headers_content_type": "headers.content-type",
"resp_content": "content"
}
def update_variables(self, variables_mapping):
""" update context variables binds with new variables mapping
"""
self.extractors.update(extract_binds)
self.variables.update(variables_mapping)
def get_eval_value(self, data):
""" evaluate data recursively, each variable in data will be evaluated.