mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-06 15:01:22 +08:00
#106: support builtin functions
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
__title__ = 'HttpRunner'
|
__title__ = 'HttpRunner'
|
||||||
__description__ = 'HTTP test runner, not just about api test and load test.'
|
__description__ = 'HTTP test runner, not just about api test and load test.'
|
||||||
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
||||||
__version__ = '0.9.7'
|
__version__ = '0.9.8'
|
||||||
__author__ = 'debugtalk'
|
__author__ = 'debugtalk'
|
||||||
__author_email__ = 'mail@debugtalk.com'
|
__author_email__ = 'mail@debugtalk.com'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
|
|||||||
@@ -703,6 +703,11 @@ class TestcaseParser(object):
|
|||||||
if item_type == "function":
|
if item_type == "function":
|
||||||
if item_name in self.functions:
|
if item_name in self.functions:
|
||||||
return self.functions[item_name]
|
return self.functions[item_name]
|
||||||
|
|
||||||
|
try:
|
||||||
|
return eval(item_name)
|
||||||
|
except NameError:
|
||||||
|
pass
|
||||||
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]
|
||||||
|
|||||||
@@ -34,3 +34,9 @@ bind_module_functions:
|
|||||||
- 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)}
|
||||||
|
|
||||||
|
builtin_functions:
|
||||||
|
variables:
|
||||||
|
- length: ${len(debugtalk)}
|
||||||
|
- smallest: ${min(2, 3, 8)}
|
||||||
|
- largest: ${max(2, 3, 8)}
|
||||||
|
|||||||
@@ -100,6 +100,25 @@ class VariableBindsUnittest(ApiServerUnittest):
|
|||||||
self.assertIn("sum2nums", context_variables)
|
self.assertIn("sum2nums", context_variables)
|
||||||
self.assertEqual(context_variables["sum2nums"], 5)
|
self.assertEqual(context_variables["sum2nums"], 5)
|
||||||
|
|
||||||
|
def test_call_builtin_functions(self):
|
||||||
|
testcase1 = {
|
||||||
|
"variables": [
|
||||||
|
{"length": "${len(debugtalk)}"},
|
||||||
|
{"smallest": "${min(2, 3, 8)}"},
|
||||||
|
{"largest": "${max(2, 3, 8)}"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
testcase2 = self.testcases["builtin_functions"]
|
||||||
|
|
||||||
|
for testcase in [testcase1, testcase2]:
|
||||||
|
variables = testcase['variables']
|
||||||
|
self.context.bind_variables(variables)
|
||||||
|
|
||||||
|
context_variables = self.context.testcase_variables_mapping
|
||||||
|
self.assertEqual(context_variables["length"], 9)
|
||||||
|
self.assertEqual(context_variables["smallest"], 2)
|
||||||
|
self.assertEqual(context_variables["largest"], 8)
|
||||||
|
|
||||||
def test_context_bind_lambda_functions_with_import(self):
|
def test_context_bind_lambda_functions_with_import(self):
|
||||||
testcase1 = {
|
testcase1 = {
|
||||||
"requires": ["random", "string", "hashlib"],
|
"requires": ["random", "string", "hashlib"],
|
||||||
|
|||||||
Reference in New Issue
Block a user