mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
deprecate function_binds
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
__title__ = 'HttpRunner'
|
__title__ = 'HttpRunner'
|
||||||
__description__ = 'One-stop solution for HTTP(S) testing.'
|
__description__ = 'One-stop solution for HTTP(S) testing.'
|
||||||
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
__url__ = 'https://github.com/HttpRunner/HttpRunner'
|
||||||
__version__ = '1.5.7'
|
__version__ = '1.5.8'
|
||||||
__author__ = 'debugtalk'
|
__author__ = 'debugtalk'
|
||||||
__author_email__ = 'mail@debugtalk.com'
|
__author_email__ = 'mail@debugtalk.com'
|
||||||
__license__ = 'MIT'
|
__license__ = 'MIT'
|
||||||
|
|||||||
@@ -45,9 +45,6 @@ class Context(object):
|
|||||||
if level == "testset":
|
if level == "testset":
|
||||||
self.testcase_parser.file_path = config_dict.get("path", None)
|
self.testcase_parser.file_path = config_dict.get("path", None)
|
||||||
|
|
||||||
function_binds = config_dict.get('function_binds', {})
|
|
||||||
self.bind_functions(function_binds, level)
|
|
||||||
|
|
||||||
variables = config_dict.get('variables') \
|
variables = config_dict.get('variables') \
|
||||||
or config_dict.get('variable_binds', OrderedDict())
|
or config_dict.get('variable_binds', OrderedDict())
|
||||||
self.bind_variables(variables, level)
|
self.bind_variables(variables, level)
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ class Runner(object):
|
|||||||
{
|
{
|
||||||
"name": "smoke testset",
|
"name": "smoke testset",
|
||||||
"path": "tests/data/demo_testset_variables.yml",
|
"path": "tests/data/demo_testset_variables.yml",
|
||||||
"function_binds": {}, # optional
|
|
||||||
"variables": [], # optional
|
"variables": [], # optional
|
||||||
"request": {
|
"request": {
|
||||||
"base_url": "http://127.0.0.1:5000",
|
"base_url": "http://127.0.0.1:5000",
|
||||||
@@ -48,7 +47,6 @@ class Runner(object):
|
|||||||
testcase:
|
testcase:
|
||||||
{
|
{
|
||||||
"name": "testcase description",
|
"name": "testcase description",
|
||||||
"function_binds": {}, # optional
|
|
||||||
"variables": [], # optional
|
"variables": [], # optional
|
||||||
"request": {
|
"request": {
|
||||||
"url": "/api/get-token",
|
"url": "/api/get-token",
|
||||||
@@ -113,7 +111,6 @@ class Runner(object):
|
|||||||
"name": "testcase description",
|
"name": "testcase description",
|
||||||
"skip": "skip this test unconditionally",
|
"skip": "skip this test unconditionally",
|
||||||
"times": 3,
|
"times": 3,
|
||||||
"function_binds": {}, # optional, override
|
|
||||||
"variables": [], # optional, override
|
"variables": [], # optional, override
|
||||||
"request": {
|
"request": {
|
||||||
"url": "http://127.0.0.1:5000/api/users/1000",
|
"url": "http://127.0.0.1:5000/api/users/1000",
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ class TestSuite(unittest.TestSuite):
|
|||||||
"name": "testset description",
|
"name": "testset description",
|
||||||
"config": {
|
"config": {
|
||||||
"name": "testset description",
|
"name": "testset description",
|
||||||
"function_binds": {},
|
|
||||||
"parameters": {},
|
"parameters": {},
|
||||||
"variables": [],
|
"variables": [],
|
||||||
"request": {},
|
"request": {},
|
||||||
|
|||||||
@@ -3,14 +3,6 @@ bind_variables:
|
|||||||
- TOKEN: "debugtalk"
|
- TOKEN: "debugtalk"
|
||||||
- token: $TOKEN
|
- token: $TOKEN
|
||||||
|
|
||||||
bind_lambda_functions:
|
|
||||||
function_binds:
|
|
||||||
add_one: "lambda x: x + 1"
|
|
||||||
add_two_nums: "lambda x, y: x + y"
|
|
||||||
variables:
|
|
||||||
- add1: ${add_one(2)}
|
|
||||||
- sum2nums: ${add_two_nums(2, 3)}
|
|
||||||
|
|
||||||
builtin_functions:
|
builtin_functions:
|
||||||
variables:
|
variables:
|
||||||
- length: ${len(debugtalk)}
|
- length: ${len(debugtalk)}
|
||||||
|
|||||||
@@ -76,30 +76,22 @@ class VariableBindsUnittest(ApiServerUnittest):
|
|||||||
self.assertEqual(testcase_variables["token"], "debugtalk")
|
self.assertEqual(testcase_variables["token"], "debugtalk")
|
||||||
|
|
||||||
def test_context_bind_lambda_functions(self):
|
def test_context_bind_lambda_functions(self):
|
||||||
testcase1 = {
|
function_binds = {
|
||||||
"function_binds": {
|
"add_one": lambda x: x + 1,
|
||||||
"add_one": lambda x: x + 1,
|
"add_two_nums": lambda x, y: x + y
|
||||||
"add_two_nums": lambda x, y: x + y
|
|
||||||
},
|
|
||||||
"variables": [
|
|
||||||
{"add1": "${add_one(2)}"},
|
|
||||||
{"sum2nums": "${add_two_nums(2,3)}"}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
testcase2 = self.testcases["bind_lambda_functions"]
|
variables = [
|
||||||
|
{"add1": "${add_one(2)}"},
|
||||||
|
{"sum2nums": "${add_two_nums(2,3)}"}
|
||||||
|
]
|
||||||
|
self.context.bind_functions(function_binds)
|
||||||
|
self.context.bind_variables(variables)
|
||||||
|
|
||||||
for testcase in [testcase1, testcase2]:
|
context_variables = self.context.testcase_variables_mapping
|
||||||
function_binds = testcase.get('function_binds', {})
|
self.assertIn("add1", context_variables)
|
||||||
self.context.bind_functions(function_binds)
|
self.assertEqual(context_variables["add1"], 3)
|
||||||
|
self.assertIn("sum2nums", context_variables)
|
||||||
variables = testcase['variables']
|
self.assertEqual(context_variables["sum2nums"], 5)
|
||||||
self.context.bind_variables(variables)
|
|
||||||
|
|
||||||
context_variables = self.context.testcase_variables_mapping
|
|
||||||
self.assertIn("add1", context_variables)
|
|
||||||
self.assertEqual(context_variables["add1"], 3)
|
|
||||||
self.assertIn("sum2nums", context_variables)
|
|
||||||
self.assertEqual(context_variables["sum2nums"], 5)
|
|
||||||
|
|
||||||
def test_call_builtin_functions(self):
|
def test_call_builtin_functions(self):
|
||||||
testcase1 = {
|
testcase1 = {
|
||||||
|
|||||||
Reference in New Issue
Block a user