mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-17 15:07:38 +08:00
@@ -1,5 +1,5 @@
|
||||
bind_variables:
|
||||
variable_binds:
|
||||
variables:
|
||||
- TOKEN: "debugtalk"
|
||||
- token: $TOKEN
|
||||
|
||||
@@ -7,7 +7,7 @@ bind_lambda_functions:
|
||||
function_binds:
|
||||
add_one: "lambda x: x + 1"
|
||||
add_two_nums: "lambda x, y: x + y"
|
||||
variable_binds:
|
||||
variables:
|
||||
- add1: ${add_one(2)}
|
||||
- sum2nums: ${add_two_nums(2, 3)}
|
||||
|
||||
@@ -19,7 +19,7 @@ bind_lambda_functions_with_import:
|
||||
function_binds:
|
||||
gen_random_string: "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))"
|
||||
gen_md5: "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
|
||||
variable_binds:
|
||||
variables:
|
||||
- TOKEN: debugtalk
|
||||
- random: ${gen_random_string(5)}
|
||||
- data: "{'name': 'user', 'password': '123456'}"
|
||||
@@ -29,7 +29,7 @@ bind_module_functions:
|
||||
function_binds:
|
||||
import_module_items:
|
||||
- tests.data.debugtalk
|
||||
variable_binds:
|
||||
variables:
|
||||
- TOKEN: debugtalk
|
||||
- random: ${gen_random_string(5)}
|
||||
- data: "{'name': 'user', 'password': '123456'}"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
||||
}
|
||||
},
|
||||
"extract_binds": [
|
||||
"extractors": [
|
||||
{
|
||||
"token": "content.token"
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
app_version: '2.8.6'
|
||||
json:
|
||||
sign: f1219719911caae89ccc301679857ebfda115ca2
|
||||
extract_binds:
|
||||
extractors:
|
||||
- token: content.token
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- config:
|
||||
name: "create user testsets."
|
||||
variable_binds:
|
||||
name: "user management testset."
|
||||
variables:
|
||||
- user_agent: 'iOS/10.3'
|
||||
- device_sn: ${gen_random_string(15)}
|
||||
- os_platform: 'ios'
|
||||
@@ -16,7 +16,7 @@
|
||||
- test:
|
||||
name: get token
|
||||
api: get_token($user_agent, $device_sn, $os_platform, $app_version)
|
||||
extract_binds:
|
||||
extractors:
|
||||
- token: content.token
|
||||
|
||||
- test:
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
- test:
|
||||
name: create user which does not exist
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
api: create_user(1000, $user_name, $user_password, $token)
|
||||
@@ -53,7 +53,7 @@
|
||||
|
||||
- test:
|
||||
name: create user which exists
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
api: create_user(1000, $user_name, $user_password, $token)
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
- test:
|
||||
name: update user which exists
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_name: "user1"
|
||||
- user_password: "654321"
|
||||
api: update_user(1000, $user_name, $user_password, $token)
|
||||
@@ -72,7 +72,7 @@
|
||||
- {"check": "content.success", "expected": true}
|
||||
|
||||
- test:
|
||||
name: get user that has been created
|
||||
name: get user that has been updated
|
||||
api: get_user(1000, $token)
|
||||
validators:
|
||||
- {"check": "status_code", "expected": 200}
|
||||
@@ -102,7 +102,7 @@
|
||||
|
||||
- test:
|
||||
name: create user which has been deleted
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
api: create_user(1000, $user_name, $user_password, $token)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name: "create user testsets."
|
||||
import_module_items:
|
||||
- tests.data.debugtalk
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_agent: 'iOS/10.3'
|
||||
- device_sn: ${gen_random_string(15)}
|
||||
- os_platform: 'ios'
|
||||
@@ -25,7 +25,7 @@
|
||||
app_version: $app_version
|
||||
json:
|
||||
sign: ${get_sign($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract_binds:
|
||||
extractors:
|
||||
- token: content.token
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
- test:
|
||||
name: create user which does not exist
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
request:
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
'DebugTalk'.encode('ascii'),
|
||||
''.join(args).encode('ascii'),
|
||||
hashlib.sha1).hexdigest()"
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_agent: 'iOS/10.3'
|
||||
- device_sn: ${gen_random_string_lambda(15)}
|
||||
- os_platform: 'ios'
|
||||
@@ -35,7 +35,7 @@
|
||||
app_version: $app_version
|
||||
json:
|
||||
sign: ${get_sign_lambda($user_agent, $device_sn, $os_platform, $app_version)}
|
||||
extract_binds:
|
||||
extractors:
|
||||
- token: content.token
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
- test:
|
||||
name: create user which does not exist
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
request:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
- config:
|
||||
name: "create user testsets."
|
||||
variable_binds:
|
||||
variables:
|
||||
- device_sn: 'HZfFBh6tU59EdXJ'
|
||||
request:
|
||||
base_url: $BASE_URL
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
- test:
|
||||
name: get token
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_agent: 'iOS/10.3'
|
||||
- os_platform: 'ios'
|
||||
- app_version: '2.8.6'
|
||||
@@ -26,7 +26,7 @@
|
||||
app_version: $app_version
|
||||
json:
|
||||
sign: $sign
|
||||
extract_binds:
|
||||
extractors:
|
||||
- token: content.token
|
||||
validators:
|
||||
- {"check": "status_code", "comparator": "eq", "expected": 200}
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
- test:
|
||||
name: create user which does not exist
|
||||
variable_binds:
|
||||
variables:
|
||||
- user_name: "user1"
|
||||
- user_password: "123456"
|
||||
request:
|
||||
|
||||
@@ -18,11 +18,11 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
self.assertIn("get_timestamp", self.context.testset_functions_config)
|
||||
self.assertIn("gen_random_string", self.context.testset_functions_config)
|
||||
|
||||
variable_binds = [
|
||||
variables = [
|
||||
{"random": "${gen_random_string(5)}"},
|
||||
{"timestamp10": "${get_timestamp(10)}"}
|
||||
]
|
||||
self.context.bind_variables(variable_binds)
|
||||
self.context.bind_variables(variables)
|
||||
context_variables = self.context.get_testcase_variables_mapping()
|
||||
|
||||
self.assertEqual(len(context_variables["random"]), 5)
|
||||
@@ -31,7 +31,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
def test_context_bind_testset_variables(self):
|
||||
# testcase in JSON format
|
||||
testcase1 = {
|
||||
"variable_binds": [
|
||||
"variables": [
|
||||
{"GLOBAL_TOKEN": "debugtalk"},
|
||||
{"token": "$GLOBAL_TOKEN"}
|
||||
]
|
||||
@@ -40,8 +40,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
testcase2 = self.testcases["bind_variables"]
|
||||
|
||||
for testcase in [testcase1, testcase2]:
|
||||
variable_binds = testcase['variable_binds']
|
||||
self.context.bind_variables(variable_binds, level="testset")
|
||||
variables = testcase['variables']
|
||||
self.context.bind_variables(variables, level="testset")
|
||||
|
||||
testset_variables = self.context.testset_shared_variables_mapping
|
||||
testcase_variables = self.context.get_testcase_variables_mapping()
|
||||
@@ -54,7 +54,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
|
||||
def test_context_bind_testcase_variables(self):
|
||||
testcase1 = {
|
||||
"variable_binds": [
|
||||
"variables": [
|
||||
{"GLOBAL_TOKEN": "debugtalk"},
|
||||
{"token": "$GLOBAL_TOKEN"}
|
||||
]
|
||||
@@ -62,8 +62,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
testcase2 = self.testcases["bind_variables"]
|
||||
|
||||
for testcase in [testcase1, testcase2]:
|
||||
variable_binds = testcase['variable_binds']
|
||||
self.context.bind_variables(variable_binds)
|
||||
variables = testcase['variables']
|
||||
self.context.bind_variables(variables)
|
||||
|
||||
testset_variables = self.context.testset_shared_variables_mapping
|
||||
testcase_variables = self.context.get_testcase_variables_mapping()
|
||||
@@ -80,7 +80,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
"add_one": lambda x: x + 1,
|
||||
"add_two_nums": lambda x, y: x + y
|
||||
},
|
||||
"variable_binds": [
|
||||
"variables": [
|
||||
{"add1": "${add_one(2)}"},
|
||||
{"sum2nums": "${add_two_nums(2,3)}"}
|
||||
]
|
||||
@@ -91,8 +91,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
function_binds = testcase.get('function_binds', {})
|
||||
self.context.bind_functions(function_binds)
|
||||
|
||||
variable_binds = testcase['variable_binds']
|
||||
self.context.bind_variables(variable_binds)
|
||||
variables = testcase['variables']
|
||||
self.context.bind_variables(variables)
|
||||
|
||||
context_variables = self.context.get_testcase_variables_mapping()
|
||||
self.assertIn("add1", context_variables)
|
||||
@@ -107,7 +107,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
"gen_random_string": "lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(str_len))",
|
||||
"gen_md5": "lambda *str_args: hashlib.md5(''.join(str_args).encode('utf-8')).hexdigest()"
|
||||
},
|
||||
"variable_binds": [
|
||||
"variables": [
|
||||
{"TOKEN": "debugtalk"},
|
||||
{"random": "${gen_random_string(5)}"},
|
||||
{"data": '{"name": "user", "password": "123456"}'},
|
||||
@@ -123,8 +123,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
function_binds = testcase.get('function_binds', {})
|
||||
self.context.bind_functions(function_binds)
|
||||
|
||||
variable_binds = testcase['variable_binds']
|
||||
self.context.bind_variables(variable_binds)
|
||||
variables = testcase['variables']
|
||||
self.context.bind_variables(variables)
|
||||
context_variables = self.context.get_testcase_variables_mapping()
|
||||
|
||||
self.assertIn("TOKEN", context_variables)
|
||||
@@ -144,7 +144,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
def test_import_module_items(self):
|
||||
testcase1 = {
|
||||
"import_module_items": ["tests.data.debugtalk"],
|
||||
"variable_binds": [
|
||||
"variables": [
|
||||
{"TOKEN": "debugtalk"},
|
||||
{"random": "${gen_random_string(5)}"},
|
||||
{"data": '{"name": "user", "password": "123456"}'},
|
||||
@@ -157,8 +157,8 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
module_items = testcase.get('import_module_items', [])
|
||||
self.context.import_module_items(module_items)
|
||||
|
||||
variable_binds = testcase['variable_binds']
|
||||
self.context.bind_variables(variable_binds)
|
||||
variables = testcase['variables']
|
||||
self.context.bind_variables(variables)
|
||||
context_variables = self.context.get_testcase_variables_mapping()
|
||||
|
||||
self.assertIn("TOKEN", context_variables)
|
||||
@@ -182,7 +182,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
test_runner = runner.Runner()
|
||||
testcase = {
|
||||
"import_module_items": ["tests.data.debugtalk"],
|
||||
"variable_binds": [
|
||||
"variables": [
|
||||
{"TOKEN": "debugtalk"},
|
||||
{"random": "${gen_random_string(5)}"},
|
||||
{"data": '{"name": "user", "password": "123456"}'},
|
||||
@@ -206,7 +206,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
||||
self.assertIn("random", parsed_request["headers"])
|
||||
self.assertEqual(len(parsed_request["headers"]["random"]), 5)
|
||||
self.assertIn("data", parsed_request)
|
||||
self.assertEqual(parsed_request["data"], testcase["variable_binds"][2]["data"])
|
||||
self.assertEqual(parsed_request["data"], testcase["variables"][2]["data"])
|
||||
self.assertEqual(parsed_request["headers"]["SECRET_KEY"], "DebugTalk")
|
||||
|
||||
def test_exec_content_functions(self):
|
||||
|
||||
@@ -53,7 +53,7 @@ class TestRunner(ApiServerUnittest):
|
||||
"sign": "f1219719911caae89ccc301679857ebfda115ca2"
|
||||
}
|
||||
},
|
||||
"extract_binds": [
|
||||
"extractors": [
|
||||
{"token": "content.token"}
|
||||
],
|
||||
"validators": [
|
||||
|
||||
@@ -55,7 +55,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_eval_content_variables(self):
|
||||
variable_binds = {
|
||||
variables = {
|
||||
"var_1": "abc",
|
||||
"var_2": "def",
|
||||
"var_3": 123,
|
||||
@@ -63,7 +63,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
"var_5": True,
|
||||
"var_6": None
|
||||
}
|
||||
testcase_parser = testcase.TestcaseParser(variables_binds=variable_binds)
|
||||
testcase_parser = testcase.TestcaseParser(variables=variables)
|
||||
self.assertEqual(
|
||||
testcase_parser.eval_content_variables("$var_1"),
|
||||
"abc"
|
||||
@@ -157,11 +157,11 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_parse_content_with_bindings_variables(self):
|
||||
variables_binds = {
|
||||
variables = {
|
||||
"str_1": "str_value1",
|
||||
"str_2": "str_value2"
|
||||
}
|
||||
testcase_parser = testcase.TestcaseParser(variables_binds=variables_binds)
|
||||
testcase_parser = testcase.TestcaseParser(variables=variables)
|
||||
self.assertEqual(
|
||||
testcase_parser.parse_content_with_bindings("$str_1"),
|
||||
"str_value1"
|
||||
@@ -184,11 +184,11 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_parse_content_with_bindings_multiple_identical_variables(self):
|
||||
variables_binds = {
|
||||
variables = {
|
||||
"userid": 100,
|
||||
"data": 1498
|
||||
}
|
||||
testcase_parser = testcase.TestcaseParser(variables_binds=variables_binds)
|
||||
testcase_parser = testcase.TestcaseParser(variables=variables)
|
||||
content = "/users/$userid/training/$data?userId=$userid&data=$data"
|
||||
self.assertEqual(
|
||||
testcase_parser.parse_content_with_bindings(content),
|
||||
@@ -196,12 +196,12 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_parse_variables_multiple_identical_variables(self):
|
||||
variables_binds = {
|
||||
variables = {
|
||||
"user": 100,
|
||||
"userid": 1000,
|
||||
"data": 1498
|
||||
}
|
||||
testcase_parser = testcase.TestcaseParser(variables_binds=variables_binds)
|
||||
testcase_parser = testcase.TestcaseParser(variables=variables)
|
||||
content = "/users/$user/$userid/$data?userId=$userid&data=$data"
|
||||
self.assertEqual(
|
||||
testcase_parser.parse_content_with_bindings(content),
|
||||
@@ -210,17 +210,17 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
|
||||
def test_parse_content_with_bindings_functions(self):
|
||||
import random, string
|
||||
functions_binds = {
|
||||
functions = {
|
||||
"gen_random_string": lambda str_len: ''.join(random.choice(string.ascii_letters + string.digits) \
|
||||
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)}")
|
||||
self.assertEqual(len(result), 5)
|
||||
|
||||
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(
|
||||
testcase_parser.parse_content_with_bindings("${add_two_nums(1)}"),
|
||||
2
|
||||
@@ -265,10 +265,10 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_eval_content_functions(self):
|
||||
functions_binds = {
|
||||
functions = {
|
||||
"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(
|
||||
testcase_parser.eval_content_functions("${add_two_nums(1, 2)}"),
|
||||
3
|
||||
@@ -289,13 +289,13 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
self.assertEqual(content, "/api/900150983cd24fb0d6963f7d28e17f72")
|
||||
|
||||
def test_parse_content_with_bindings_testcase(self):
|
||||
variables_binds = {
|
||||
variables = {
|
||||
"uid": "1000",
|
||||
"random": "A2dEx",
|
||||
"authorization": "a83de0ff8d2e896dbd8efb81ba14e17d",
|
||||
"data": {"name": "user", "password": "123456"}
|
||||
}
|
||||
functions_binds = {
|
||||
functions = {
|
||||
"add_two_nums": lambda a, b=1: a + b,
|
||||
"get_timestamp": lambda: int(time.time() * 1000)
|
||||
}
|
||||
@@ -310,7 +310,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
},
|
||||
"body": "$data"
|
||||
}
|
||||
parsed_testcase = testcase.TestcaseParser(variables_binds, functions_binds)\
|
||||
parsed_testcase = testcase.TestcaseParser(variables, functions)\
|
||||
.parse_content_with_bindings(testcase_template)
|
||||
|
||||
self.assertEqual(
|
||||
@@ -319,15 +319,15 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(
|
||||
parsed_testcase["headers"]["authorization"],
|
||||
variables_binds["authorization"]
|
||||
variables["authorization"]
|
||||
)
|
||||
self.assertEqual(
|
||||
parsed_testcase["headers"]["random"],
|
||||
variables_binds["random"]
|
||||
variables["random"]
|
||||
)
|
||||
self.assertEqual(
|
||||
parsed_testcase["body"],
|
||||
variables_binds["data"]
|
||||
variables["data"]
|
||||
)
|
||||
self.assertEqual(
|
||||
parsed_testcase["headers"]["sum"],
|
||||
@@ -417,7 +417,7 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
path = os.path.join(
|
||||
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
||||
testsets_list = testcase.load_testcases_by_path(path)
|
||||
self.assertIn("variable_binds", testsets_list[0]["config"])
|
||||
self.assertIn("variables", testsets_list[0]["config"])
|
||||
self.assertIn("request", testsets_list[0]["config"])
|
||||
self.assertIn("request", testsets_list[0]["testcases"][0])
|
||||
self.assertIn("url", testsets_list[0]["testcases"][0]["request"])
|
||||
|
||||
Reference in New Issue
Block a user