mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-20 07:40:32 +08:00
call HttpRunner class with testsets data structure other than path
This commit is contained in:
@@ -9,6 +9,53 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
|
||||
def setUp(self):
|
||||
self.testset_path = "tests/data/demo_testset_cli.yml"
|
||||
self.testset = {
|
||||
'name': 'testset description',
|
||||
'config': {
|
||||
'path': 'docs/data/demo-quickstart-2.yml',
|
||||
'name': 'testset description',
|
||||
'request': {
|
||||
'base_url': '',
|
||||
'headers': {'User-Agent': 'python-requests/2.18.4'}
|
||||
},
|
||||
'variables': [],
|
||||
'output': ['token']
|
||||
},
|
||||
'api': {},
|
||||
'testcases': [
|
||||
{
|
||||
'name': '/api/get-token',
|
||||
'request': {
|
||||
'url': 'http://127.0.0.1:5000/api/get-token',
|
||||
'method': 'POST',
|
||||
'headers': {'Content-Type': 'application/json', 'app_version': '2.8.6', 'device_sn': 'FwgRiO7CNA50DSU', 'os_platform': 'ios', 'user_agent': 'iOS/10.3'},
|
||||
'json': {'sign': '958a05393efef0ac7c0fb80a7eac45e24fd40c27'}
|
||||
},
|
||||
'extract': [
|
||||
{'token': 'content.token'}
|
||||
],
|
||||
'validate': [
|
||||
{'eq': ['status_code', 200]},
|
||||
{'eq': ['headers.Content-Type', 'application/json']},
|
||||
{'eq': ['content.success', True]}
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': '/api/users/1000',
|
||||
'request': {
|
||||
'url': 'http://127.0.0.1:5000/api/users/1000',
|
||||
'method': 'POST',
|
||||
'headers': {'Content-Type': 'application/json', 'device_sn': 'FwgRiO7CNA50DSU','token': '$token'}, 'json': {'name': 'user1', 'password': '123456'}
|
||||
},
|
||||
'validate': [
|
||||
{'eq': ['status_code', 201]},
|
||||
{'eq': ['headers.Content-Type', 'application/json']},
|
||||
{'eq': ['content.success', True]},
|
||||
{'eq': ['content.msg', 'user created successfully.']}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
self.reset_all()
|
||||
|
||||
def reset_all(self):
|
||||
@@ -35,3 +82,19 @@ class TestHttpRunner(ApiServerUnittest):
|
||||
runner.gen_html_report(html_report_name=output_folder_name)
|
||||
report_save_dir = os.path.join(os.getcwd(), 'reports', output_folder_name)
|
||||
shutil.rmtree(report_save_dir)
|
||||
|
||||
def test_run_testsets(self):
|
||||
testsets = [self.testset]
|
||||
runner = HttpRunner().run(testsets)
|
||||
summary = runner.summary
|
||||
self.assertTrue(summary["success"])
|
||||
self.assertEqual(summary["stat"]["testsRun"], 2)
|
||||
self.assertIn("records", summary)
|
||||
|
||||
def test_run_testset(self):
|
||||
testsets = self.testset
|
||||
runner = HttpRunner().run(testsets)
|
||||
summary = runner.summary
|
||||
self.assertTrue(summary["success"])
|
||||
self.assertEqual(summary["stat"]["testsRun"], 2)
|
||||
self.assertIn("records", summary)
|
||||
|
||||
@@ -24,9 +24,57 @@ class TestTask(ApiServerUnittest):
|
||||
self.assertIsInstance(testcase, task.TestCase)
|
||||
|
||||
def test_create_task(self):
|
||||
testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_testset_variables.yml')
|
||||
task_suite = task.TaskSuite(testcase_file_path)
|
||||
self.assertEqual(task_suite.countTestCases(), 3)
|
||||
testsets = [
|
||||
{
|
||||
'name': 'testset description',
|
||||
'config': {
|
||||
'path': 'docs/data/demo-quickstart-2.yml',
|
||||
'name': 'testset description',
|
||||
'request': {
|
||||
'base_url': '',
|
||||
'headers': {'User-Agent': 'python-requests/2.18.4'}
|
||||
},
|
||||
'variables': [],
|
||||
'output': ['token']
|
||||
},
|
||||
'api': {},
|
||||
'testcases': [
|
||||
{
|
||||
'name': '/api/get-token',
|
||||
'request': {
|
||||
'url': 'http://127.0.0.1:5000/api/get-token',
|
||||
'method': 'POST',
|
||||
'headers': {'Content-Type': 'application/json', 'app_version': '2.8.6', 'device_sn': 'FwgRiO7CNA50DSU', 'os_platform': 'ios', 'user_agent': 'iOS/10.3'},
|
||||
'json': {'sign': '958a05393efef0ac7c0fb80a7eac45e24fd40c27'}
|
||||
},
|
||||
'extract': [
|
||||
{'token': 'content.token'}
|
||||
],
|
||||
'validate': [
|
||||
{'eq': ['status_code', 200]},
|
||||
{'eq': ['headers.Content-Type', 'application/json']},
|
||||
{'eq': ['content.success', True]}
|
||||
]
|
||||
},
|
||||
{
|
||||
'name': '/api/users/1000',
|
||||
'request': {
|
||||
'url': 'http://127.0.0.1:5000/api/users/1000',
|
||||
'method': 'POST',
|
||||
'headers': {'Content-Type': 'application/json', 'device_sn': 'FwgRiO7CNA50DSU','token': '$token'}, 'json': {'name': 'user1', 'password': '123456'}
|
||||
},
|
||||
'validate': [
|
||||
{'eq': ['status_code', 201]},
|
||||
{'eq': ['headers.Content-Type', 'application/json']},
|
||||
{'eq': ['content.success', True]},
|
||||
{'eq': ['content.msg', 'user created successfully.']}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
task_suite = task.TaskSuite(testsets)
|
||||
self.assertEqual(task_suite.countTestCases(), 2)
|
||||
for suite in task_suite:
|
||||
for testcase in suite:
|
||||
self.assertIsInstance(testcase, task.TestCase)
|
||||
|
||||
@@ -738,3 +738,32 @@ class TestcaseParserUnittest(unittest.TestCase):
|
||||
{"var3": "val3"},
|
||||
merged_extractors
|
||||
)
|
||||
|
||||
def test_is_testsets(self):
|
||||
data_structure = "path/to/file"
|
||||
self.assertFalse(testcase.is_testsets(data_structure))
|
||||
data_structure = ["path/to/file1", "path/to/file2"]
|
||||
self.assertFalse(testcase.is_testsets(data_structure))
|
||||
|
||||
data_structure = {
|
||||
"name": "desc1",
|
||||
"config": {},
|
||||
"api": {},
|
||||
"testcases": ["testcase11", "testcase12"]
|
||||
}
|
||||
self.assertTrue(data_structure)
|
||||
data_structure = [
|
||||
{
|
||||
"name": "desc1",
|
||||
"config": {},
|
||||
"api": {},
|
||||
"testcases": ["testcase11", "testcase12"]
|
||||
},
|
||||
{
|
||||
"name": "desc2",
|
||||
"config": {},
|
||||
"api": {},
|
||||
"testcases": ["testcase21", "testcase22"]
|
||||
}
|
||||
]
|
||||
self.assertTrue(data_structure)
|
||||
|
||||
Reference in New Issue
Block a user