Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
"validate": [
{"check": "status_code", "expect": 200}
],
"teardown_hooks": ["${teardown_hook_sleep_N_secs($response, 2)}"]
}
]
}
]
tests_mapping = {
"project_mapping": {
"functions": self.debugtalk_functions
},
"testcases": testcases
}
parsed_testcases = parser.parse_tests(tests_mapping)
parsed_testcase = parsed_testcases[0]
test_runner = runner.Runner(parsed_testcase["config"])
start_time = time.time()
test_runner.run_test(parsed_testcase["teststeps"][0])
end_time = time.time()
# check if teardown function executed
self.assertLess(end_time - start_time, 0.5)
'variables': {
"host": "https://github.com"
},
"verify": False
},
"teststeps": [
{
'name': 'testcase1',
"base_url": "",
'request': {'url': '/api1', 'method': 'GET', "verify": True}
}
]
}
]
}
parsed_testcases = parser.parse_tests(tests_mapping)
test_dict = parsed_testcases[0]["teststeps"][0]
self.assertEqual(str(test_dict["base_url"]), 'LazyString($host)')
self.assertEqual(test_dict["request"]["verify"], True)
def test_testsuite_run_suite(self):
testcase_path = "tests/testsuites/create_users.yml"
tests_mapping = loader.load_cases(testcase_path)
testcases = parser.parse_tests(tests_mapping)
runner = HttpRunner()
test_suite = runner._add_tests(testcases)
tests_results = runner._run_suite(test_suite)
self.assertEqual(len(tests_results[0][1].records), 2)
results = tests_results[0][1]
self.assertIn(
"setup and reset all (override)",
results.records[0]["name"]
)
self.assertEqual(
results.records[1]["name"],
"create user and check result."
)
def test_testcase_simple_run_suite(self):
testcase_path = "tests/testcases/setup.yml"
tests_mapping = loader.load_tests(testcase_path)
testcases = parser.parse_tests(tests_mapping)
runner = HttpRunner()
test_suite = runner._add_tests(testcases)
tests_results = runner._run_suite(test_suite)
self.assertEqual(len(tests_results[0][1].records), 2)
{
"config": {
'name': 'bugfix verify',
"base_url": "https://httpbin.org/",
"verify": True
},
"teststeps": [
{
'name': 'testcase1',
'request': {'url': '/headers', 'method': 'GET', "verify": False}
}
]
}
]
}
parsed_testcases = parser.parse_tests(tests_mapping)
test_dict = parsed_testcases[0]["teststeps"][0]
self.assertEqual(test_dict["request"]["verify"], False)
"host2": "https://httprunner.org",
"num4": "${sum_two($num0, 5)}",
"num3": "${sum_two($num2, 4)}",
"num2": "${sum_two($num1, 3)}",
"num1": "${sum_two(1, 2)}"
},
'request': {
'url': '/api1/?num1=$num1&num2=$num2&num3=$num3&num4=$num4',
'method': 'GET'
}
}
]
}
]
}
parser.parse_tests(tests_mapping)
parse_failed_testfiles = parser.get_parse_failed_testfiles()
self.assertIn("testcase", parse_failed_testfiles)
def test_testcase_add_tests(self):
testcase_path = "tests/testcases/setup.yml"
tests_mapping = loader.load_tests(testcase_path)
testcases = parser.parse_tests(tests_mapping)
runner = HttpRunner()
test_suite = runner._add_tests(testcases)
self.assertEqual(len(test_suite._tests), 1)
teststeps = test_suite._tests[0].teststeps
self.assertEqual(teststeps[0]["name"], "get token (setup)")
self.assertEqual(teststeps[0]["variables"]["device_sn"], "TESTCASE_SETUP_XXX")
self.assertIn("api", teststeps[0])
def test_testcase_parser(self):
testcase_path = "tests/testcases/setup.yml"
tests_mapping = loader.load_cases(testcase_path)
parsed_testcases = parser.parse_tests(tests_mapping)
self.assertEqual(len(parsed_testcases), 1)
self.assertIn("variables", parsed_testcases[0]["config"])
self.assertEqual(len(parsed_testcases[0]["teststeps"]), 2)
test_dict1 = parsed_testcases[0]["teststeps"][0]
self.assertEqual(test_dict1["name"], "get token (setup)")
self.assertNotIn("api_def", test_dict1)
self.assertEqual(test_dict1["variables"]["device_sn"], "TESTCASE_SETUP_XXX")
self.assertEqual(test_dict1["request"]["url"], "/api/get-token")
self.assertEqual(test_dict1["request"]["verify"], False)
test_dict2 = parsed_testcases[0]["teststeps"][1]
self.assertEqual(test_dict2["request"]["verify"], False)
{
"config": {
'name': 'bugfix verify',
"base_url": "https://httpbin.org/",
"verify": False
},
"teststeps": [
{
'name': 'testcase1',
'request': {'url': '/headers', 'method': 'GET'}
}
]
}
]
}
parsed_testcases = parser.parse_tests(tests_mapping)
test_dict = parsed_testcases[0]["teststeps"][0]
self.assertEqual(test_dict["request"]["verify"], False)