Exemplo n.º 1
0
    def test_load_testcases_by_path_files(self):
        testsets_list = []

        # absolute file path
        path = os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.json')
        testset_list = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list), 1)
        self.assertEqual(len(testset_list[0]["testcases"]), 2)
        testsets_list.extend(testset_list)

        # relative file path
        path = 'test/data/simple_demo_no_auth.yml'
        testset_list = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list), 1)
        self.assertEqual(len(testset_list[0]["testcases"]), 2)
        testsets_list.extend(testset_list)

        # list/set container with file(s)
        path = [
            os.path.join(os.getcwd(), 'test/data/simple_demo_no_auth.json'),
            'test/data/simple_demo_no_auth.yml'
        ]
        testset_list = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list), 2)
        self.assertEqual(len(testset_list[0]["testcases"]), 2)
        self.assertEqual(len(testset_list[1]["testcases"]), 2)
        testsets_list.extend(testset_list)
        self.assertEqual(len(testsets_list), 4)

        for testset in testsets_list:
            for testcase in testset["testcases"]:
                self.assertIn('name', testcase)
                self.assertIn('request', testcase)
                self.assertIn('url', testcase['request'])
                self.assertIn('method', testcase['request'])
Exemplo n.º 2
0
    def test_load_testcases_by_path_folder(self):
        # absolute folder path
        path = os.path.join(os.getcwd(), 'test/data')
        testset_list_1 = utils.load_testcases_by_path(path)
        self.assertGreater(len(testset_list_1), 6)

        # relative folder path
        path = 'test/data/'
        testset_list_2 = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list_1), len(testset_list_2))

        # list/set container with file(s)
        path = [os.path.join(os.getcwd(), 'test/data'), 'test/data/']
        testset_list_3 = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list_3), 2 * len(testset_list_1))
Exemplo n.º 3
0
 def test_run_testsets_template_import_functions(self):
     testcase_file_path = os.path.join(
         os.getcwd(), 'tests/data/demo_testset_template_import_functions.yml')
     testsets = utils.load_testcases_by_path(testcase_file_path)
     results = self.test_runner.run_testsets(testsets)
     self.assertEqual(len(results), 1)
     self.assertEqual(results, [[True] * 3])
Exemplo n.º 4
0
 def test_run_testsets_template_yaml(self):
     testcase_file_path = os.path.join(
         os.getcwd(), 'test/data/demo_template_sets.yml')
     testsets = utils.load_testcases_by_path(testcase_file_path)
     results = self.test_runner.run_testsets(testsets)
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0], [(True, []), (True, [])])
Exemplo n.º 5
0
 def test_run_testsets_auth_json(self):
     testcase_file_path = os.path.join(
         os.getcwd(), 'test/data/simple_demo_auth_hardcode.json')
     testsets = utils.load_testcases_by_path(testcase_file_path)
     results = self.test_runner.run_testsets(testsets)
     self.assertEqual(len(results), 1)
     self.assertEqual(results[0], [(True, []), (True, [])])
Exemplo n.º 6
0
 def test_run_testset_yaml_success(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)
     results = self.test_runner.run_testset(testsets[0])
     self.assertEqual(len(results), 2)
     self.assertEqual(results, [(True, {}), (True, {})])
Exemplo n.º 7
0
 def test_run_testsets_template_lambda_functions(self):
     testcase_file_path = os.path.join(
         os.getcwd(), 'tests/data/demo_testset_template_lambda_functions.yml')
     testsets = utils.load_testcases_by_path(testcase_file_path)
     results = self.test_runner.run_testsets(testsets)
     self.assertEqual(len(results), 1)
     self.assertEqual(results, [[(True, [])] * 3])
Exemplo n.º 8
0
 def test_run_testset_template_import_functions(self):
     testcase_file_path = os.path.join(
         os.getcwd(), 'test/data/demo_import_functions.yml')
     testsets = utils.load_testcases_by_path(testcase_file_path)
     results = self.test_runner.run_testset(testsets[0])
     self.assertEqual(len(results), 2)
     self.assertEqual(results, [(True, []), (True, [])])
Exemplo n.º 9
0
 def test_run_testset_template_variables(self):
     testcase_file_path = os.path.join(
         os.getcwd(), 'tests/data/demo_testset_variables.yml')
     testsets = utils.load_testcases_by_path(testcase_file_path)
     results = self.test_runner.run_testset(testsets[0])
     self.assertEqual(len(results), 3)
     self.assertEqual(results, [True] * 3)
Exemplo n.º 10
0
 def test_run_testset_template_variables(self):
     testcase_file_path = os.path.join(
         os.getcwd(), 'tests/data/demo_testset_variables.yml')
     testsets = utils.load_testcases_by_path(testcase_file_path)
     results = self.test_runner.run_testset(testsets[0])
     self.assertEqual(len(results), 3)
     self.assertEqual(results, [True] * 3)
Exemplo n.º 11
0
 def test_create_suite(self):
     testcase_file_path = os.path.join(os.getcwd(), 'tests/data/demo_testset_variables.yml')
     testsets = utils.load_testcases_by_path(testcase_file_path)
     suite = task.create_suite(testsets[0])
     self.assertEqual(suite.countTestCases(), 3)
     for testcase in suite:
         self.assertIsInstance(testcase, task.ApiTestCase)
Exemplo n.º 12
0
 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 = task.create_suite(testsets[0])
     self.assertEqual(suite.countTestCases(), 2)
     for testcase in suite:
         self.assertIsInstance(testcase, task.ApiTestCase)
Exemplo n.º 13
0
    def test_load_testcases_by_path_not_exist(self):
        # absolute folder path
        path = os.path.join(os.getcwd(), 'tests/data_not_exist')
        testset_list_1 = utils.load_testcases_by_path(path)
        self.assertEqual(testset_list_1, [])

        # relative folder path
        path = 'tests/data_not_exist'
        testset_list_2 = utils.load_testcases_by_path(path)
        self.assertEqual(testset_list_2, [])

        # list/set container with file(s)
        path = [
            os.path.join(os.getcwd(), 'tests/data_not_exist'),
            'tests/data_not_exist/'
        ]
        testset_list_3 = utils.load_testcases_by_path(path)
        self.assertEqual(testset_list_3, [])
Exemplo n.º 14
0
    def test_load_testcases_by_path_folder(self):
        # absolute folder path
        path = os.path.join(os.getcwd(), 'tests/data')
        testset_list_1 = utils.load_testcases_by_path(path)
        self.assertGreater(len(testset_list_1), 5)

        # relative folder path
        path = 'tests/data/'
        testset_list_2 = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list_1), len(testset_list_2))

        # list/set container with file(s)
        path = [
            os.path.join(os.getcwd(), 'tests/data'),
            'tests/data/'
        ]
        testset_list_3 = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list_3), 2 * len(testset_list_1))
Exemplo n.º 15
0
    def test_load_testcases_by_path_not_exist(self):
        # absolute folder path
        path = os.path.join(os.getcwd(), 'test/data_not_exist')
        testset_list_1 = utils.load_testcases_by_path(path)
        self.assertEqual(testset_list_1, [])

        # relative folder path
        path = 'test/data_not_exist'
        testset_list_2 = utils.load_testcases_by_path(path)
        self.assertEqual(testset_list_2, [])

        # list/set container with file(s)
        path = [
            os.path.join(os.getcwd(), 'test/data_not_exist'),
            'test/data_not_exist/'
        ]
        testset_list_3 = utils.load_testcases_by_path(path)
        self.assertEqual(testset_list_3, [])
Exemplo n.º 16
0
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
Exemplo n.º 17
0
    def test_load_testcases_by_path_files(self):
        testsets_list = []

        # absolute file path
        path = os.path.join(
            os.getcwd(), 'tests/data/demo_testset_hardcode.json')
        testset_list = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list), 1)
        self.assertEqual(len(testset_list[0]["testcases"]), 3)
        testsets_list.extend(testset_list)

        # relative file path
        path = 'tests/data/demo_testset_hardcode.yml'
        testset_list = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list), 1)
        self.assertEqual(len(testset_list[0]["testcases"]), 3)
        testsets_list.extend(testset_list)

        # list/set container with file(s)
        path = [
            os.path.join(os.getcwd(), 'tests/data/demo_testset_hardcode.json'),
            'tests/data/demo_testset_hardcode.yml'
        ]
        testset_list = utils.load_testcases_by_path(path)
        self.assertEqual(len(testset_list), 2)
        self.assertEqual(len(testset_list[0]["testcases"]), 3)
        self.assertEqual(len(testset_list[1]["testcases"]), 3)
        testsets_list.extend(testset_list)
        self.assertEqual(len(testsets_list), 4)

        for testset in testsets_list:
            for testcase in testset["testcases"]:
                self.assertIn('name', testcase)
                self.assertIn('request', testcase)
                self.assertIn('url', testcase['request'])
                self.assertIn('method', testcase['request'])
Exemplo n.º 18
0
def gen_locustfile(testcase_file_path):
    """ generate locustfile from template.
    """
    locustfile_path = 'locustfile.py'
    template_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                 'locustfile_template')
    testsets = load_testcases_by_path(testcase_file_path)
    host = testsets[0].get("config", {}).get("request", {}).get("base_url", "")

    with codecs.open(template_path, encoding='utf-8') as template:
        with codecs.open(locustfile_path, 'w', encoding='utf-8') as locustfile:
            template_content = template.read()
            template_content = template_content.replace("$HOST", host)
            template_content = template_content.replace(
                "$TESTCASE_FILE", testcase_file_path)
            locustfile.write(template_content)

    return locustfile_path
Exemplo n.º 19
0
 def test_run_testset_hardcode(self):
     for testcase_file_path in self.testcase_file_path_list:
         testsets = utils.load_testcases_by_path(testcase_file_path)
         results = self.test_runner.run_testset(testsets[0])
         self.assertEqual(len(results), 3)
         self.assertEqual(results, [(True, [])] * 3)
Exemplo n.º 20
0
 def test_run_testsets_hardcode(self):
     for testcase_file_path in self.testcase_file_path_list:
         testsets = utils.load_testcases_by_path(testcase_file_path)
         results = self.test_runner.run_testsets(testsets)
         self.assertEqual(len(results), 1)
         self.assertEqual(results, [[True] * 3])
Exemplo n.º 21
0
 def test_run_testsets_hardcode(self):
     for testcase_file_path in self.testcase_file_path_list:
         testsets = utils.load_testcases_by_path(testcase_file_path)
         results = self.test_runner.run_testsets(testsets)
         self.assertEqual(len(results), 1)
         self.assertEqual(results, [[True] * 3])