mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 07:57:27 +08:00
rename functions
This commit is contained in:
@@ -22,5 +22,4 @@ class WebPageUser(HttpLocust):
|
|||||||
min_wait = 1000
|
min_wait = 1000
|
||||||
max_wait = 5000
|
max_wait = 5000
|
||||||
|
|
||||||
testsets = testcase.load_testcases_by_path("$TESTCASE_FILE")
|
testset = testcase.load_test_file("$TESTCASE_FILE")
|
||||||
testset = testsets[0]
|
|
||||||
|
|||||||
+3
-3
@@ -3,7 +3,7 @@ import multiprocessing
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from ate.testcase import load_testcases_by_path
|
from ate.testcase import load_test_file
|
||||||
from locust.main import main
|
from locust.main import main
|
||||||
|
|
||||||
|
|
||||||
@@ -36,8 +36,8 @@ def gen_locustfile(testcase_file_path):
|
|||||||
os.path.dirname(os.path.realpath(__file__)),
|
os.path.dirname(os.path.realpath(__file__)),
|
||||||
'locustfile_template'
|
'locustfile_template'
|
||||||
)
|
)
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testset = load_test_file(testcase_file_path)
|
||||||
host = testsets[0].get("config", {}).get("request", {}).get("base_url", "")
|
host = testset.get("config", {}).get("request", {}).get("base_url", "")
|
||||||
|
|
||||||
with codecs.open(template_path, encoding='utf-8') as template:
|
with codecs.open(template_path, encoding='utf-8') as template:
|
||||||
with codecs.open(locustfile_path, 'w', encoding='utf-8') as locustfile:
|
with codecs.open(locustfile_path, 'w', encoding='utf-8') as locustfile:
|
||||||
|
|||||||
+8
-8
@@ -117,8 +117,11 @@ def load_testcases_by_path(path):
|
|||||||
return load_testcases_by_path(files_list)
|
return load_testcases_by_path(files_list)
|
||||||
|
|
||||||
elif os.path.isfile(path):
|
elif os.path.isfile(path):
|
||||||
return load_test_file(path)
|
testset = load_test_file(path)
|
||||||
|
if testset["testcases"] or testset["api"]:
|
||||||
|
return [testset]
|
||||||
|
else:
|
||||||
|
return []
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -141,9 +144,9 @@ def load_test_file(file_path):
|
|||||||
"api": {},
|
"api": {},
|
||||||
"testcases": []
|
"testcases": []
|
||||||
}
|
}
|
||||||
testcases_list = utils.load_testcases(file_path)
|
tests_list = utils.load_tests(file_path)
|
||||||
|
|
||||||
for item in testcases_list:
|
for item in tests_list:
|
||||||
for key in item:
|
for key in item:
|
||||||
if key == "config":
|
if key == "config":
|
||||||
testset["config"].update(item["config"])
|
testset["config"].update(item["config"])
|
||||||
@@ -170,10 +173,7 @@ def load_test_file(file_path):
|
|||||||
api_info.update(item["api"])
|
api_info.update(item["api"])
|
||||||
testset["api"][func_name] = api_info
|
testset["api"][func_name] = api_info
|
||||||
|
|
||||||
if testset["testcases"] or testset["api"]:
|
return testset
|
||||||
return [testset]
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
def load_testcases_by_call(test_block_dict, call_type):
|
def load_testcases_by_call(test_block_dict, call_type):
|
||||||
call_func = test_block_dict[call_type]
|
call_func = test_block_dict[call_type]
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ def load_json_file(json_file):
|
|||||||
with codecs.open(json_file, encoding='utf-8') as data_file:
|
with codecs.open(json_file, encoding='utf-8') as data_file:
|
||||||
return json.load(data_file)
|
return json.load(data_file)
|
||||||
|
|
||||||
def load_testcases(testcase_file_path):
|
def load_tests(testcase_file_path):
|
||||||
file_suffix = os.path.splitext(testcase_file_path)[1]
|
file_suffix = os.path.splitext(testcase_file_path)[1]
|
||||||
if file_suffix == '.json':
|
if file_suffix == '.json':
|
||||||
return load_json_file(testcase_file_path)
|
return load_json_file(testcase_file_path)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class VariableBindsUnittest(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.context = Context()
|
self.context = Context()
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml')
|
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_binds.yml')
|
||||||
self.testcases = utils.load_testcases(testcase_file_path)
|
self.testcases = utils.load_tests(testcase_file_path)
|
||||||
|
|
||||||
def test_context_init_functions(self):
|
def test_context_init_functions(self):
|
||||||
self.assertIn("get_timestamp", self.context.testset_functions_config)
|
self.assertIn("get_timestamp", self.context.testset_functions_config)
|
||||||
|
|||||||
+17
-17
@@ -1,8 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from ate import exception, runner, utils
|
from ate import exception, runner, testcase, utils
|
||||||
from ate.testcase import load_testcases_by_path
|
|
||||||
from tests.base import ApiServerUnittest
|
from tests.base import ApiServerUnittest
|
||||||
|
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ class TestRunner(ApiServerUnittest):
|
|||||||
|
|
||||||
def test_run_single_testcase(self):
|
def test_run_single_testcase(self):
|
||||||
for testcase_file_path in self.testcase_file_path_list:
|
for testcase_file_path in self.testcase_file_path_list:
|
||||||
testcases = utils.load_testcases(testcase_file_path)
|
testcases = utils.load_tests(testcase_file_path)
|
||||||
testcase = testcases[0]["test"]
|
testcase = testcases[0]["test"]
|
||||||
self.assertTrue(self.test_runner.run_test(testcase))
|
self.assertTrue(self.test_runner.run_test(testcase))
|
||||||
|
|
||||||
@@ -67,66 +67,66 @@ class TestRunner(ApiServerUnittest):
|
|||||||
|
|
||||||
def test_run_testset_hardcode(self):
|
def test_run_testset_hardcode(self):
|
||||||
for testcase_file_path in self.testcase_file_path_list:
|
for testcase_file_path in self.testcase_file_path_list:
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testset = testcase.load_test_file(testcase_file_path)
|
||||||
result = self.test_runner.run_testset(testsets[0])
|
result = self.test_runner.run_testset(testset)
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
|
|
||||||
def test_run_testsets_hardcode(self):
|
def test_run_testsets_hardcode(self):
|
||||||
for testcase_file_path in self.testcase_file_path_list:
|
for testcase_file_path in self.testcase_file_path_list:
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testsets = testcase.load_testcases_by_path(testcase_file_path)
|
||||||
result = self.test_runner.run_testsets(testsets)
|
result = self.test_runner.run_testsets(testsets)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
def test_run_testset_template_variables(self):
|
def test_run_testset_template_variables(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testset = testcase.load_test_file(testcase_file_path)
|
||||||
result = self.test_runner.run_testset(testsets[0])
|
result = self.test_runner.run_testset(testset)
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
|
|
||||||
def test_run_testset_template_import_functions(self):
|
def test_run_testset_template_import_functions(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_template_import_functions.yml')
|
os.getcwd(), 'tests/data/demo_testset_template_import_functions.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testset = testcase.load_test_file(testcase_file_path)
|
||||||
result = self.test_runner.run_testset(testsets[0])
|
result = self.test_runner.run_testset(testset)
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
|
|
||||||
def test_run_testsets_template_import_functions(self):
|
def test_run_testsets_template_import_functions(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_template_import_functions.yml')
|
os.getcwd(), 'tests/data/demo_testset_template_import_functions.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testsets = testcase.load_testcases_by_path(testcase_file_path)
|
||||||
result = self.test_runner.run_testsets(testsets)
|
result = self.test_runner.run_testsets(testsets)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
def test_run_testsets_template_lambda_functions(self):
|
def test_run_testsets_template_lambda_functions(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_template_lambda_functions.yml')
|
os.getcwd(), 'tests/data/demo_testset_template_lambda_functions.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testsets = testcase.load_testcases_by_path(testcase_file_path)
|
||||||
result = self.test_runner.run_testsets(testsets)
|
result = self.test_runner.run_testsets(testsets)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
def test_run_testset_layered(self):
|
def test_run_testset_layered(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testsets = testcase.load_testcases_by_path(testcase_file_path)
|
||||||
result = self.test_runner.run_testsets(testsets)
|
result = self.test_runner.run_testsets(testsets)
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
|
||||||
def test_run_testset_output(self):
|
def test_run_testset_output(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testset = testcase.load_test_file(testcase_file_path)
|
||||||
result = self.test_runner.run_testset(testsets[0])
|
result = self.test_runner.run_testset(testset)
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
self.assertIn("token", result["output"])
|
self.assertIn("token", result["output"])
|
||||||
|
|
||||||
def test_run_testset_with_variables_mapping(self):
|
def test_run_testset_with_variables_mapping(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
os.getcwd(), 'tests/data/demo_testset_layer.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testset = testcase.load_test_file(testcase_file_path)
|
||||||
variables_mapping = {
|
variables_mapping = {
|
||||||
"app_version": '2.9.7'
|
"app_version": '2.9.7'
|
||||||
}
|
}
|
||||||
result = self.test_runner.run_testset(testsets[0], variables_mapping)
|
result = self.test_runner.run_testset(testset, variables_mapping)
|
||||||
self.assertTrue(result["success"])
|
self.assertTrue(result["success"])
|
||||||
self.assertIn("token", result["output"])
|
self.assertIn("token", result["output"])
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from ate import task
|
from ate import task
|
||||||
from ate.testcase import load_testcases_by_path
|
from ate.testcase import load_test_file
|
||||||
from tests.base import ApiServerUnittest
|
from tests.base import ApiServerUnittest
|
||||||
|
|
||||||
|
|
||||||
@@ -17,8 +17,8 @@ class TestTask(ApiServerUnittest):
|
|||||||
|
|
||||||
def test_create_suite(self):
|
def test_create_suite(self):
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
||||||
testsets = load_testcases_by_path(testcase_file_path)
|
testset = load_test_file(testcase_file_path)
|
||||||
suite = task.ApiTestSuite(testsets[0])
|
suite = task.ApiTestSuite(testset)
|
||||||
self.assertEqual(suite.countTestCases(), 3)
|
self.assertEqual(suite.countTestCases(), 3)
|
||||||
for testcase in suite:
|
for testcase in suite:
|
||||||
self.assertIsInstance(testcase, task.ApiTestCase)
|
self.assertIsInstance(testcase, task.ApiTestCase)
|
||||||
|
|||||||
+3
-3
@@ -9,12 +9,12 @@ class TestUtils(ApiServerUnittest):
|
|||||||
|
|
||||||
def test_load_testcases_bad_filepath(self):
|
def test_load_testcases_bad_filepath(self):
|
||||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo')
|
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo')
|
||||||
self.assertEqual(utils.load_testcases(testcase_file_path), [])
|
self.assertEqual(utils.load_tests(testcase_file_path), [])
|
||||||
|
|
||||||
def test_load_json_testcases(self):
|
def test_load_json_testcases(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_hardcode.json')
|
os.getcwd(), 'tests/data/demo_testset_hardcode.json')
|
||||||
testcases = utils.load_testcases(testcase_file_path)
|
testcases = utils.load_tests(testcase_file_path)
|
||||||
self.assertEqual(len(testcases), 3)
|
self.assertEqual(len(testcases), 3)
|
||||||
testcase = testcases[0]["test"]
|
testcase = testcases[0]["test"]
|
||||||
self.assertIn('name', testcase)
|
self.assertIn('name', testcase)
|
||||||
@@ -25,7 +25,7 @@ class TestUtils(ApiServerUnittest):
|
|||||||
def test_load_yaml_testcases(self):
|
def test_load_yaml_testcases(self):
|
||||||
testcase_file_path = os.path.join(
|
testcase_file_path = os.path.join(
|
||||||
os.getcwd(), 'tests/data/demo_testset_hardcode.yml')
|
os.getcwd(), 'tests/data/demo_testset_hardcode.yml')
|
||||||
testcases = utils.load_testcases(testcase_file_path)
|
testcases = utils.load_tests(testcase_file_path)
|
||||||
self.assertEqual(len(testcases), 3)
|
self.assertEqual(len(testcases), 3)
|
||||||
testcase = testcases[0]["test"]
|
testcase = testcases[0]["test"]
|
||||||
self.assertIn('name', testcase)
|
self.assertIn('name', testcase)
|
||||||
|
|||||||
Reference in New Issue
Block a user