mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-04 23:16:57 +08:00
refactor: import built_in module
This commit is contained in:
+8
-11
@@ -5,7 +5,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from httprunner import exceptions, logger, testcase, utils
|
from httprunner import built_in, exceptions, logger, testcase, utils
|
||||||
from httprunner.compat import OrderedDict
|
from httprunner.compat import OrderedDict
|
||||||
|
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ class Context(object):
|
|||||||
self.testcase_parser.update_binded_variables(self.testcase_variables_mapping)
|
self.testcase_parser.update_binded_variables(self.testcase_variables_mapping)
|
||||||
|
|
||||||
if level == "testset":
|
if level == "testset":
|
||||||
self.import_module_items(["httprunner.built_in"], "testset")
|
self.import_module_items(built_in)
|
||||||
|
|
||||||
def config_context(self, config_dict, level):
|
def config_context(self, config_dict, level):
|
||||||
if level == "testset":
|
if level == "testset":
|
||||||
@@ -66,17 +66,14 @@ class Context(object):
|
|||||||
|
|
||||||
self.__update_context_functions_config(level, eval_function_binds)
|
self.__update_context_functions_config(level, eval_function_binds)
|
||||||
|
|
||||||
def import_module_items(self, modules, level="testcase"):
|
def import_module_items(self, imported_module):
|
||||||
""" import modules and bind all functions within the context
|
""" import module functions and variables and bind to testset context
|
||||||
"""
|
"""
|
||||||
sys.path.insert(0, os.getcwd())
|
imported_functions_dict = utils.filter_module(imported_module, "function")
|
||||||
for module_name in modules:
|
self.__update_context_functions_config("testset", imported_functions_dict)
|
||||||
imported_module = utils.get_imported_module(module_name)
|
|
||||||
imported_functions_dict = utils.filter_module(imported_module, "function")
|
|
||||||
self.__update_context_functions_config(level, imported_functions_dict)
|
|
||||||
|
|
||||||
imported_variables_dict = utils.filter_module(imported_module, "variable")
|
imported_variables_dict = utils.filter_module(imported_module, "variable")
|
||||||
self.bind_variables(imported_variables_dict, level)
|
self.bind_variables(imported_variables_dict, "testset")
|
||||||
|
|
||||||
def bind_variables(self, variables, level="testcase"):
|
def bind_variables(self, variables, level="testcase"):
|
||||||
""" bind variables to testset context or current testcase context.
|
""" bind variables to testset context or current testcase context.
|
||||||
|
|||||||
@@ -113,15 +113,14 @@ class VariableBindsUnittest(ApiServerUnittest):
|
|||||||
self.assertEqual(context_variables["largest"], 8)
|
self.assertEqual(context_variables["largest"], 8)
|
||||||
|
|
||||||
def test_import_module_items(self):
|
def test_import_module_items(self):
|
||||||
module_items = ["tests.debugtalk"]
|
|
||||||
variables = [
|
variables = [
|
||||||
{"TOKEN": "debugtalk"},
|
{"TOKEN": "debugtalk"},
|
||||||
{"random": "${gen_random_string(5)}"},
|
{"random": "${gen_random_string(5)}"},
|
||||||
{"data": '{"name": "user", "password": "123456"}'},
|
{"data": '{"name": "user", "password": "123456"}'},
|
||||||
{"authorization": "${gen_md5($TOKEN, $data, $random)}"}
|
{"authorization": "${gen_md5($TOKEN, $data, $random)}"}
|
||||||
]
|
]
|
||||||
|
from tests import debugtalk
|
||||||
self.context.import_module_items(module_items)
|
self.context.import_module_items(debugtalk)
|
||||||
self.context.bind_variables(variables)
|
self.context.bind_variables(variables)
|
||||||
context_variables = self.context.testcase_variables_mapping
|
context_variables = self.context.testcase_variables_mapping
|
||||||
|
|
||||||
@@ -163,7 +162,8 @@ class VariableBindsUnittest(ApiServerUnittest):
|
|||||||
"data": "$data"
|
"data": "$data"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.context.import_module_items(["tests.debugtalk"])
|
from tests import debugtalk
|
||||||
|
self.context.import_module_items(debugtalk)
|
||||||
self.context.bind_variables(testcase["variables"])
|
self.context.bind_variables(testcase["variables"])
|
||||||
parsed_request = self.context.get_parsed_request(testcase["request"])
|
parsed_request = self.context.get_parsed_request(testcase["request"])
|
||||||
self.assertIn("authorization", parsed_request["headers"])
|
self.assertIn("authorization", parsed_request["headers"])
|
||||||
|
|||||||
Reference in New Issue
Block a user