mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-26 02:40:05 +08:00
remove debugtalk.py variables mechanism
This commit is contained in:
@@ -94,4 +94,4 @@
|
||||
- ${teardown_hook_sleep_N_secs($response, $n_secs)}
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- contained_by: [content.headers.Host, $HTTPBIN_SERVER]
|
||||
- contained_by: [content.headers.Host, "${get_httpbin_server()}"]
|
||||
|
||||
27
tests/data/bugfix_parameters.yml
Normal file
27
tests/data/bugfix_parameters.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
# fix #258
|
||||
- config:
|
||||
name: "user management testcase."
|
||||
variables:
|
||||
- user_agent: 'iOS/10.3'
|
||||
- device_sn: ${gen_random_string(15)}
|
||||
- os_platform: 'ios'
|
||||
- app_version: '2.8.6'
|
||||
parameters:
|
||||
- user_agent: ['iOS', 'android']
|
||||
request:
|
||||
base_url: ${get_base_url()}
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
device_sn: $device_sn
|
||||
output:
|
||||
- token
|
||||
|
||||
- test:
|
||||
name: get token with $user_agent, $app_version
|
||||
api: get_token($user_agent, $device_sn, $os_platform, $app_version)
|
||||
extract:
|
||||
- token: content.token
|
||||
validate:
|
||||
- "eq": ["status_code", 200]
|
||||
- "len_eq": ["content.token", 16]
|
||||
- "contains": [{"a": 1, "b": 2}, "b"]
|
||||
@@ -10,7 +10,7 @@
|
||||
- os_platform: 'ios'
|
||||
- app_version: 2.8.5
|
||||
request:
|
||||
base_url: $BASE_URL
|
||||
base_url: ${get_base_url()}
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
device_sn: $device_sn
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
- [11, 21]
|
||||
- [12, 22]
|
||||
- "app_version": "${gen_app_version()}"
|
||||
request: $demo_default_request
|
||||
request: ${get_default_request()}
|
||||
|
||||
- test:
|
||||
name: testcase1-$var_a
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
- os_platform: 'ios'
|
||||
- app_version: '2.8.6'
|
||||
request:
|
||||
base_url: $BASE_URL
|
||||
base_url: ${get_base_url()}
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
device_sn: $device_sn
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
- os_platform: 'ios'
|
||||
- app_version: '2.8.6'
|
||||
request:
|
||||
base_url: $BASE_URL
|
||||
base_url: ${get_base_url()}
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
device_sn: $device_sn
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
variables:
|
||||
- device_sn: 'HZfFBh6tU59EdXJ'
|
||||
request:
|
||||
base_url: $BASE_URL
|
||||
base_url: ${get_base_url()}
|
||||
headers:
|
||||
Content-Type: application/json
|
||||
device_sn: $device_sn
|
||||
|
||||
@@ -4,17 +4,23 @@ import random
|
||||
import string
|
||||
import time
|
||||
|
||||
from tests.api_server import HTTPBIN_SERVER, SECRET_KEY, gen_md5, get_sign
|
||||
from tests.api_server import HTTPBIN_SERVER, gen_md5, get_sign
|
||||
|
||||
BASE_URL = "http://127.0.0.1:5000"
|
||||
|
||||
def get_httpbin_server():
|
||||
return HTTPBIN_SERVER
|
||||
|
||||
demo_default_request = {
|
||||
"base_url": "$BASE_URL",
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
def get_base_url():
|
||||
return BASE_URL
|
||||
|
||||
def get_default_request():
|
||||
return {
|
||||
"base_url": BASE_URL,
|
||||
"headers": {
|
||||
"content-type": "application/json"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def sum_two(m, n):
|
||||
return m + n
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
- config:
|
||||
name: basic test with httpbin
|
||||
request:
|
||||
base_url: $HTTPBIN_SERVER
|
||||
base_url: ${get_httpbin_server()}
|
||||
setup_hooks:
|
||||
- ${hook_print(setup)}
|
||||
teardown_hooks:
|
||||
@@ -19,7 +19,7 @@
|
||||
- ${teardown_hook_sleep_N_secs($response, 1)}
|
||||
validate:
|
||||
- eq: ["status_code", 200]
|
||||
- contained_by: [content.headers.Host, $HTTPBIN_SERVER]
|
||||
- contained_by: [content.headers.Host, "${get_httpbin_server()}"]
|
||||
|
||||
- test:
|
||||
name: alter response
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
- config:
|
||||
name: load images
|
||||
request:
|
||||
base_url: $HTTPBIN_SERVER
|
||||
base_url: ${get_httpbin_server()}
|
||||
|
||||
- test:
|
||||
name: get png image
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
- config:
|
||||
name: test upload file with httpbin
|
||||
request:
|
||||
base_url: $HTTPBIN_SERVER
|
||||
base_url: ${get_httpbin_server()}
|
||||
|
||||
- test:
|
||||
name: upload file
|
||||
|
||||
@@ -312,7 +312,7 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
summary = runner.summary
|
||||
self.assertTrue(summary["success"])
|
||||
self.assertIn("token", summary["details"][0]["in_out"]["out"])
|
||||
self.assertGreater(len(summary["details"][0]["in_out"]["in"]), 7)
|
||||
self.assertGreater(len(summary["details"][0]["in_out"]["in"]), 3)
|
||||
|
||||
def test_run_testcase_with_parameters(self):
|
||||
testcase_file_path = os.path.join(
|
||||
|
||||
@@ -10,11 +10,9 @@ class TestContext(ApiServerUnittest):
|
||||
|
||||
def setUp(self):
|
||||
project_mapping = loader.load_project_tests(os.path.join(os.getcwd(), "tests"))
|
||||
self.debugtalk_module = project_mapping["debugtalk"]
|
||||
|
||||
self.context = context.Context(
|
||||
self.debugtalk_module["variables"],
|
||||
self.debugtalk_module["functions"]
|
||||
variables={"SECRET_KEY": "DebugTalk"},
|
||||
functions=project_mapping["functions"]
|
||||
)
|
||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml')
|
||||
self.testcases = loader.load_file(testcase_file_path)
|
||||
|
||||
@@ -191,57 +191,21 @@ class TestFileLoader(unittest.TestCase):
|
||||
class TestModuleLoader(unittest.TestCase):
|
||||
|
||||
def test_filter_module_functions(self):
|
||||
module_mapping = loader.load_python_module(loader)
|
||||
functions_dict = module_mapping["functions"]
|
||||
self.assertIn("load_python_module", functions_dict)
|
||||
self.assertNotIn("is_py3", functions_dict)
|
||||
module_functions = loader.load_module_functions(loader)
|
||||
self.assertIn("load_module_functions", module_functions)
|
||||
self.assertNotIn("is_py3", module_functions)
|
||||
|
||||
def test_load_debugtalk_module(self):
|
||||
project_mapping = loader.load_project_tests(os.path.join(os.getcwd(), "httprunner"))
|
||||
imported_module_items = project_mapping["debugtalk"]
|
||||
self.assertNotIn("SECRET_KEY", imported_module_items["variables"])
|
||||
self.assertNotIn("alter_response", imported_module_items["functions"])
|
||||
self.assertNotIn("alter_response", project_mapping["functions"])
|
||||
|
||||
project_mapping = loader.load_project_tests(os.path.join(os.getcwd(), "tests"))
|
||||
imported_module_items = project_mapping["debugtalk"]
|
||||
self.assertEqual(
|
||||
imported_module_items["variables"]["SECRET_KEY"],
|
||||
"DebugTalk"
|
||||
)
|
||||
self.assertIn("alter_response", imported_module_items["functions"])
|
||||
self.assertIn("alter_response", project_mapping["functions"])
|
||||
|
||||
is_status_code_200 = imported_module_items["functions"]["is_status_code_200"]
|
||||
is_status_code_200 = project_mapping["functions"]["is_status_code_200"]
|
||||
self.assertTrue(is_status_code_200(200))
|
||||
self.assertFalse(is_status_code_200(500))
|
||||
|
||||
def test_get_module_item_functions(self):
|
||||
from httprunner import utils
|
||||
module_mapping = loader.load_python_module(utils)
|
||||
|
||||
get_uniform_comparator = loader.get_module_item(
|
||||
module_mapping, "functions", "get_uniform_comparator")
|
||||
self.assertTrue(validator.is_function(("get_uniform_comparator", get_uniform_comparator)))
|
||||
self.assertEqual(get_uniform_comparator("=="), "equals")
|
||||
|
||||
with self.assertRaises(exceptions.FunctionNotFound):
|
||||
loader.get_module_item(module_mapping, "functions", "gen_md4")
|
||||
|
||||
def test_get_module_item_variables(self):
|
||||
dot_env_path = os.path.join(
|
||||
os.getcwd(), "tests", ".env"
|
||||
)
|
||||
loader.load_dot_env_file(dot_env_path)
|
||||
|
||||
from tests import debugtalk
|
||||
module_mapping = loader.load_python_module(debugtalk)
|
||||
|
||||
SECRET_KEY = loader.get_module_item(module_mapping, "variables", "SECRET_KEY")
|
||||
self.assertTrue(validator.is_variable(("SECRET_KEY", SECRET_KEY)))
|
||||
self.assertEqual(SECRET_KEY, "DebugTalk")
|
||||
|
||||
with self.assertRaises(exceptions.VariableNotFound):
|
||||
loader.get_module_item(module_mapping, "variables", "SECRET_KEY2")
|
||||
|
||||
def test_locate_debugtalk_py(self):
|
||||
debugtalk_path = loader.locate_debugtalk_py("tests/data/demo_testcase.yml")
|
||||
self.assertEqual(
|
||||
@@ -268,12 +232,12 @@ class TestModuleLoader(unittest.TestCase):
|
||||
self.assertIsInstance(testcases, list)
|
||||
self.assertEqual(
|
||||
testcases[0]["config"]["request"],
|
||||
'$demo_default_request'
|
||||
'${get_default_request()}'
|
||||
)
|
||||
self.assertEqual(testcases[0]["config"]["name"], '123$var_a')
|
||||
self.assertIn(
|
||||
"sum_two",
|
||||
testcases[0]["config"]["refs"]["debugtalk"]["functions"]
|
||||
testcases[0]["config"]["refs"]["functions"]
|
||||
)
|
||||
|
||||
|
||||
@@ -427,22 +391,14 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
testcases_list = loader.load_tests(path)
|
||||
self.assertEqual(len(testcases_list), 1)
|
||||
self.assertEqual(len(testcases_list[0]["teststeps"]), 3)
|
||||
self.assertEqual(
|
||||
testcases_list[0]["config"]["refs"]["debugtalk"]["variables"]["SECRET_KEY"],
|
||||
"DebugTalk"
|
||||
)
|
||||
self.assertIn("get_sign", testcases_list[0]["config"]["refs"]["debugtalk"]["functions"])
|
||||
self.assertIn("get_sign", testcases_list[0]["config"]["refs"]["functions"])
|
||||
|
||||
# relative file path
|
||||
path = 'tests/data/demo_testcase_hardcode.yml'
|
||||
testcases_list = loader.load_tests(path)
|
||||
self.assertEqual(len(testcases_list), 1)
|
||||
self.assertEqual(len(testcases_list[0]["teststeps"]), 3)
|
||||
self.assertEqual(
|
||||
testcases_list[0]["config"]["refs"]["debugtalk"]["variables"]["SECRET_KEY"],
|
||||
"DebugTalk"
|
||||
)
|
||||
self.assertIn("get_sign", testcases_list[0]["config"]["refs"]["debugtalk"]["functions"])
|
||||
self.assertIn("get_sign", testcases_list[0]["config"]["refs"]["functions"])
|
||||
|
||||
# list/set container with file(s)
|
||||
path = [
|
||||
@@ -556,7 +512,6 @@ class TestSuiteLoader(unittest.TestCase):
|
||||
|
||||
def test_load_project_tests(self):
|
||||
project_mapping = loader.load_project_tests(os.path.join(os.getcwd(), "tests"))
|
||||
self.assertEqual(project_mapping["debugtalk"]["variables"]["SECRET_KEY"], "DebugTalk")
|
||||
self.assertIn("get_token", project_mapping["def-api"])
|
||||
self.assertIn("setup_and_reset", project_mapping["def-testcase"])
|
||||
self.assertEqual(project_mapping["env"]["PROJECT_KEY"], "ABCDEFGH")
|
||||
|
||||
@@ -389,11 +389,11 @@ class TestParser(unittest.TestCase):
|
||||
)
|
||||
loader.load_dot_env_file(dot_env_path)
|
||||
from tests import debugtalk
|
||||
debugtalk_module = loader.load_python_module(debugtalk)
|
||||
functions = loader.load_module_functions(debugtalk)
|
||||
cartesian_product_parameters = parser.parse_parameters(
|
||||
parameters,
|
||||
debugtalk_module["variables"],
|
||||
debugtalk_module["functions"]
|
||||
{},
|
||||
functions
|
||||
)
|
||||
self.assertEqual(
|
||||
len(cartesian_product_parameters),
|
||||
@@ -424,7 +424,7 @@ class TestParser(unittest.TestCase):
|
||||
{"username-password": "${parameterize(tests/data/account.csv)}"}
|
||||
]
|
||||
variables_mapping = {}
|
||||
functions_mapping = project_mapping["debugtalk"]["functions"]
|
||||
functions_mapping = project_mapping["functions"]
|
||||
testcase_path = os.path.join(
|
||||
os.getcwd(),
|
||||
"tests/data/demo_parameters.yml"
|
||||
@@ -445,11 +445,7 @@ class TestParser(unittest.TestCase):
|
||||
self.assertEqual(len(parsed_testcases), 2 * 2)
|
||||
self.assertEqual(
|
||||
parsed_testcases[0]["config"]["request"]["base_url"],
|
||||
'$BASE_URL'
|
||||
)
|
||||
self.assertEqual(
|
||||
parsed_testcases[0]["config"]["variables"]["BASE_URL"],
|
||||
'http://127.0.0.1:5000'
|
||||
"http://127.0.0.1:5000"
|
||||
)
|
||||
self.assertIsInstance(parsed_testcases, list)
|
||||
self.assertEqual(parsed_testcases[0]["config"]["name"], '12311')
|
||||
|
||||
@@ -8,8 +8,7 @@ from tests.base import ApiServerUnittest
|
||||
class TestResponse(ApiServerUnittest):
|
||||
|
||||
def setUp(self):
|
||||
module_mapping = loader.load_python_module(built_in)
|
||||
self.functions_mapping = module_mapping["functions"]
|
||||
self.functions_mapping = loader.load_module_functions(built_in)
|
||||
|
||||
def test_parse_response_object_json(self):
|
||||
url = "http://127.0.0.1:5000/api/users"
|
||||
|
||||
@@ -11,10 +11,10 @@ class TestRunner(ApiServerUnittest):
|
||||
|
||||
def setUp(self):
|
||||
project_mapping = loader.load_project_tests(os.path.join(os.getcwd(), "tests"))
|
||||
self.debugtalk_module = project_mapping["debugtalk"]
|
||||
self.debugtalk_functions = project_mapping["functions"]
|
||||
config_dict = {
|
||||
"variables": self.debugtalk_module["variables"],
|
||||
"functions": self.debugtalk_module["functions"]
|
||||
"variables": {},
|
||||
"functions": self.debugtalk_functions
|
||||
}
|
||||
self.test_runner = runner.Runner(config_dict)
|
||||
self.reset_all()
|
||||
@@ -36,8 +36,8 @@ class TestRunner(ApiServerUnittest):
|
||||
testcases = loader.load_file(testcase_file_path)
|
||||
|
||||
config_dict = {
|
||||
"variables": self.debugtalk_module["variables"],
|
||||
"functions": self.debugtalk_module["functions"]
|
||||
"variables": {},
|
||||
"functions": self.debugtalk_functions
|
||||
}
|
||||
test_runner = runner.Runner(config_dict)
|
||||
|
||||
@@ -81,8 +81,8 @@ class TestRunner(ApiServerUnittest):
|
||||
|
||||
config_dict = {
|
||||
"name": "basic test with httpbin",
|
||||
"variables": self.debugtalk_module["variables"],
|
||||
"functions": self.debugtalk_module["functions"],
|
||||
"variables": {},
|
||||
"functions": self.debugtalk_functions,
|
||||
"request": {
|
||||
"base_url": HTTPBIN_SERVER
|
||||
},
|
||||
@@ -130,8 +130,8 @@ class TestRunner(ApiServerUnittest):
|
||||
def test_run_testcase_with_hooks_modify_request(self):
|
||||
config_dict = {
|
||||
"name": "basic test with httpbin",
|
||||
"variables": self.debugtalk_module["variables"],
|
||||
"functions": self.debugtalk_module["functions"],
|
||||
"variables": {},
|
||||
"functions": self.debugtalk_functions,
|
||||
"request": {
|
||||
"base_url": HTTPBIN_SERVER
|
||||
}
|
||||
|
||||
@@ -101,8 +101,7 @@ class TestUtils(ApiServerUnittest):
|
||||
|
||||
def current_validators(self):
|
||||
from httprunner import built_in
|
||||
module_mapping = loader.load_python_module(built_in)
|
||||
functions_mapping = module_mapping["functions"]
|
||||
functions_mapping = loader.load_module_functions(built_in)
|
||||
|
||||
functions_mapping["equals"](None, None)
|
||||
functions_mapping["equals"](1, 1)
|
||||
|
||||
Reference in New Issue
Block a user