start entrance

This commit is contained in:
debugtalk
2017-06-27 19:29:44 +08:00
parent acdd5599a4
commit baf2d1c8b6
2 changed files with 92 additions and 0 deletions

62
ate/main.py Normal file
View File

@@ -0,0 +1,62 @@
import argparse
import unittest
from ate import runner, utils
class ApiTestCase(unittest.TestCase):
""" create a testcase.
"""
def __init__(self, test_runner, testcase):
super(ApiTestCase, self).__init__()
self.test_runner = test_runner
self.testcase = testcase
def runTest(self):
""" run testcase and check result.
"""
result = self.test_runner.run_test(self.testcase)
self.assertEqual(result, (True, {}))
def create_suite(testset):
""" create test suite with a testset, it may include one or several testcases.
each suite should initialize a seperate TestRunner() with testset config.
"""
suite = unittest.TestSuite()
test_runner = runner.TestRunner()
config_dict = testset.get("config", {})
test_runner.pre_config(config_dict)
testcases = testset.get("testcases", [])
for testcase in testcases:
test = ApiTestCase(test_runner, testcase)
suite.addTest(test)
return suite
def create_task(testcase_path):
""" create test task suite with specified testcase path.
each task suite may include one or several test suite.
"""
task_suite = unittest.TestSuite()
testsets = utils.load_testcases_by_path(testcase_path)
for testset in testsets:
suite = create_suite(testset)
task_suite.addTest(suite)
return task_suite
def main():
""" parse command line options and run commands.
"""
parser = argparse.ArgumentParser(
description='Api Test Engine.')
parser.add_argument(
'--testcase-path', default='testcases',
help="testcase file path")
args = parser.parse_args()
task_suite = create_task(args.testcase_path)
unittest.TextTestRunner().run(task_suite)

30
test/test_main.py Normal file
View File

@@ -0,0 +1,30 @@
import os
import random
import requests
from test.base import ApiServerUnittest
from ate import main, utils
class TestMain(ApiServerUnittest):
def setUp(self):
self.clear_users()
def clear_users(self):
url = "http://127.0.0.1:5000/api/users"
return requests.delete(url)
def test_create_suite(self):
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.yml')
testsets = utils.load_testcases_by_path(testcase_file_path)
suite = main.create_suite(testsets[0])
self.assertEqual(suite.countTestCases(), 2)
for testcase in suite:
self.assertIsInstance(testcase, main.ApiTestCase)
def test_create_task(self):
testcase_file_path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.yml')
task_suite = main.create_task(testcase_file_path)
self.assertEqual(task_suite.countTestCases(), 2)
for suite in task_suite:
for testcase in suite:
self.assertIsInstance(testcase, main.ApiTestCase)