mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-03 14:59:38 +08:00
rename TestcaseParser argument name: functions_binds => functions
This commit is contained in:
@@ -329,9 +329,9 @@ def substitute_variables_with_mapping(content, mapping):
|
|||||||
|
|
||||||
class TestcaseParser(object):
|
class TestcaseParser(object):
|
||||||
|
|
||||||
def __init__(self, variables={}, functions_binds={}, file_path=None):
|
def __init__(self, variables={}, functions={}, file_path=None):
|
||||||
self.bind_variables(variables)
|
self.bind_variables(variables)
|
||||||
self.bind_functions(functions_binds)
|
self.bind_functions(functions)
|
||||||
self.file_path = file_path
|
self.file_path = file_path
|
||||||
|
|
||||||
def bind_variables(self, variables):
|
def bind_variables(self, variables):
|
||||||
@@ -346,19 +346,19 @@ class TestcaseParser(object):
|
|||||||
"""
|
"""
|
||||||
self.variables = variables
|
self.variables = variables
|
||||||
|
|
||||||
def bind_functions(self, functions_binds):
|
def bind_functions(self, functions):
|
||||||
""" bind functions to current testcase parser
|
""" bind functions to current testcase parser
|
||||||
@param (dict) functions_binds, functions binds mapping
|
@param (dict) functions, functions binds mapping
|
||||||
{
|
{
|
||||||
"add_two_nums": lambda a, b=1: a + b
|
"add_two_nums": lambda a, b=1: a + b
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
self.functions_binds = functions_binds
|
self.functions = functions
|
||||||
|
|
||||||
def get_bind_item(self, item_type, item_name):
|
def get_bind_item(self, item_type, item_name):
|
||||||
if item_type == "function":
|
if item_type == "function":
|
||||||
if item_name in self.functions_binds:
|
if item_name in self.functions:
|
||||||
return self.functions_binds[item_name]
|
return self.functions[item_name]
|
||||||
elif item_type == "variable":
|
elif item_type == "variable":
|
||||||
if item_name in self.variables:
|
if item_name in self.variables:
|
||||||
return self.variables[item_name]
|
return self.variables[item_name]
|
||||||
|
|||||||
@@ -210,17 +210,17 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_parse_content_with_bindings_functions(self):
|
def test_parse_content_with_bindings_functions(self):
|
||||||
import random, string
|
import random, string
|
||||||
functions_binds = {
|
functions = {
|
||||||
"gen_random_string": lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) \
|
"gen_random_string": lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) \
|
||||||
for _ in range(str_len))
|
for _ in range(str_len))
|
||||||
}
|
}
|
||||||
testcase_parser = testcase.TestcaseParser(functions_binds=functions_binds)
|
testcase_parser = testcase.TestcaseParser(functions=functions)
|
||||||
|
|
||||||
result = testcase_parser.parse_content_with_bindings("${gen_random_string(5)}")
|
result = testcase_parser.parse_content_with_bindings("${gen_random_string(5)}")
|
||||||
self.assertEqual(len(result), 5)
|
self.assertEqual(len(result), 5)
|
||||||
|
|
||||||
add_two_nums = lambda a, b=1: a + b
|
add_two_nums = lambda a, b=1: a + b
|
||||||
functions_binds["add_two_nums"] = add_two_nums
|
functions["add_two_nums"] = add_two_nums
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
testcase_parser.parse_content_with_bindings("${add_two_nums(1)}"),
|
testcase_parser.parse_content_with_bindings("${add_two_nums(1)}"),
|
||||||
2
|
2
|
||||||
@@ -265,10 +265,10 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_eval_content_functions(self):
|
def test_eval_content_functions(self):
|
||||||
functions_binds = {
|
functions = {
|
||||||
"add_two_nums": lambda a, b=1: a + b
|
"add_two_nums": lambda a, b=1: a + b
|
||||||
}
|
}
|
||||||
testcase_parser = testcase.TestcaseParser(functions_binds=functions_binds)
|
testcase_parser = testcase.TestcaseParser(functions=functions)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
testcase_parser.eval_content_functions("${add_two_nums(1, 2)}"),
|
testcase_parser.eval_content_functions("${add_two_nums(1, 2)}"),
|
||||||
3
|
3
|
||||||
@@ -295,7 +295,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
"authorization": "a83de0ff8d2e896dbd8efb81ba14e17d",
|
"authorization": "a83de0ff8d2e896dbd8efb81ba14e17d",
|
||||||
"data": {"name": "user", "password": "123456"}
|
"data": {"name": "user", "password": "123456"}
|
||||||
}
|
}
|
||||||
functions_binds = {
|
functions = {
|
||||||
"add_two_nums": lambda a, b=1: a + b,
|
"add_two_nums": lambda a, b=1: a + b,
|
||||||
"get_timestamp": lambda: int(time.time() * 1000)
|
"get_timestamp": lambda: int(time.time() * 1000)
|
||||||
}
|
}
|
||||||
@@ -310,7 +310,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
|||||||
},
|
},
|
||||||
"body": "$data"
|
"body": "$data"
|
||||||
}
|
}
|
||||||
parsed_testcase = testcase.TestcaseParser(variables, functions_binds)\
|
parsed_testcase = testcase.TestcaseParser(variables, functions)\
|
||||||
.parse_content_with_bindings(testcase_template)
|
.parse_content_with_bindings(testcase_template)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
|
|||||||
Reference in New Issue
Block a user