mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-31 13:29:35 +08:00
bind_extractors: Bind named extractors to value within the context.
This commit is contained in:
@@ -8,6 +8,7 @@ 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
|
||||
@@ -44,6 +45,20 @@ 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"
|
||||
}
|
||||
"""
|
||||
self.extractors.update(extract_binds)
|
||||
|
||||
def get_eval_value(self, data):
|
||||
""" evaluate data recursively, each variable in data will be evaluated.
|
||||
variables marker: ${variable}.
|
||||
|
||||
Reference in New Issue
Block a user