Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __form_body(self, variables):
data = self.data
if data is None:
data = read_file(fill_template_str(self.file, variables))
return fill_template_str(data, variables)
def _form_request(self, url, variables: dict) -> dict:
headers = dict([(fill_template_str(k, variables), fill_template_str(v, variables))
for k, v in self.headers.items()])
rq = dict(verify=self.verify, headers=headers, files=self.__form_files(variables))
isjson, body = self.__form_body(variables)
debug('http ' + str(self.method) + ' ' + str(url) + ', ' + str(headers) + ', ' + str(body))
content_type = self.__get_content_type(headers)
if isjson or isinstance(body, dict): # contains tojson or dict supplied
if isinstance(body, dict) and content_type == 'application/json':
# json body formed manually via python dict
rq['json'] = body
else: # json string or form-data dict
rq['data'] = body
else: # raw body (or body is None)
rq['data'] = body
rq['timeout'] = self.timeout
return rq
def prepare_variables(self, test, global_variables: dict):
"""
Create variables for test
:param global_variables:
:param test: test with test variables
"""
# system env + inventory
# (test template is filled in based on system, inventory & cmd vars)
test.variables = try_get_object(fill_template_str(test.variables,
merge_two_dicts(global_variables, self._cmd_env)))
# test local
global_variables.update(test.variables)
# include vars override test local
global_variables.update(self._prepare_include_vars(test, global_variables))
# cmd_env override everything
global_variables.update(self._cmd_env)
test.variables = global_variables
def simple_input(self, variables):
"""
Use this method to get simple input as python object, with all
templates filled in
:param variables:
:return: python object
"""
json_args = fill_template_str(json.dumps(self.data), variables)
return try_get_objects(json_args)