add unittest for running single api

This commit is contained in:
debugtalk
2018-12-16 00:38:02 +08:00
parent 3249394732
commit dcd50579a1
3 changed files with 19 additions and 3 deletions

View File

@@ -211,10 +211,10 @@ class HttpRunner(object):
dict: valid testcase/testsuite data
"""
if validator.is_testcases(path_or_tests):
return self.run_tests(path_or_tests)
elif validator.is_testcase_path(path_or_tests):
if validator.is_testcase_path(path_or_tests):
return self.run_path(path_or_tests, dot_env_path, mapping)
elif validator.is_testcases(path_or_tests):
return self.run_tests(path_or_tests)
else:
raise exceptions.ParamsError("invalid testcase path or testcases.")

View File

@@ -0,0 +1,8 @@
name: headers
request:
url: http://httpbin.org/headers
method: GET
validate:
- eq: ["status_code", 200]
- eq: [content.headers.Host, "httpbin.org"]

View File

@@ -279,6 +279,14 @@ class TestHttpRunner(ApiServerUnittest):
self.assertFalse(summary["success"])
self.assertEqual(summary["stat"]["errors"], 1)
def test_run_api(self):
path = "tests/httpbin/api/get_headers.yml"
self.runner.run(path)
summary = self.runner.summary
self.assertTrue(summary["success"])
self.assertEqual(summary["stat"]["testsRun"], 1)
self.assertEqual(summary["stat"]["successes"], 1)
def test_run_testcase_hardcode(self):
for testcase_file_path in self.testcase_file_path_list:
self.runner.run(testcase_file_path)