Beispiel #1
0
 def test_validate_exception(self):
     testcases = [{
         "config": {
             'name': "test validation"
         },
         "teststeps": [{
             "name":
             "test validation",
             "request": {
                 "url": "http://127.0.0.1:5000/",
                 "method": "GET",
             },
             "variables": {
                 "resp_status_code": 200,
                 "resp_body_success": True
             },
             "validate": [{
                 "eq": ["$resp_status_code", 201]
             }, {
                 "check": "$resp_status_code",
                 "expect": 201
             }, {
                 "check": "$resp_body_success",
                 "comparator": "eq",
                 "expect": True
             }]
         }]
     }]
     tests_mapping = {"testcases": testcases}
     testcases = parser.parse_tests(tests_mapping)
     parsed_testcase = testcases[0]
     test_runner = runner.Runner(parsed_testcase["config"])
     teststep = parsed_testcase["teststeps"][0]
     with self.assertRaises(exceptions.ValidationFailure):
         test_runner.run_test(teststep)
Beispiel #2
0
def prepare_locust_tests(path):
    """ prepare locust testcases

    Args:
        path (str): testcase file path.

    Returns:
        list: locust tests data

            [
                testcase1_dict,
                testcase2_dict
            ]

    """
    tests_mapping = loader.load_cases(path)
    testcases = parser.parse_tests(tests_mapping)

    locust_tests = []

    for testcase in testcases:
        testcase_weight = testcase.get("config", {}).pop("weight", 1)
        for _ in range(testcase_weight):
            locust_tests.append(testcase)

    return locust_tests
Beispiel #3
0
 def test_testcase_simple_run_suite(self):
     testcase_path = "tests/testcases/setup.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)
Beispiel #4
0
    def test_testsuite_add_tests(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)

        self.assertEqual(len(test_suite._tests), 2)
        tests = test_suite._tests[0].teststeps
        self.assertIn("setup and reset all (override)", tests[0]["config"]["name"].raw_string)
Beispiel #5
0
    def test_testcase_add_tests(self):
        testcase_path = "tests/testcases/setup.yml"
        tests_mapping = loader.load_cases(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])
Beispiel #6
0
    def test_testcase_complex_verify(self):
        testcase_path = "tests/testcases/create_user.yml"
        tests_mapping = loader.load_cases(testcase_path)
        testcases = parser.parse_tests(tests_mapping)
        teststeps = testcases[0]["teststeps"]

        # testcases/setup.yml
        teststep0 = teststeps[0]
        self.assertEqual(teststep0["teststeps"][0]["request"]["verify"], False)
        self.assertEqual(teststep0["teststeps"][1]["request"]["verify"], False)

        # testcases/create_user.yml
        teststep1 = teststeps[1]
        self.assertEqual(teststep1["teststeps"][0]["request"]["verify"], True)
        self.assertEqual(teststep1["teststeps"][1]["request"]["verify"], True)
        self.assertEqual(teststep1["teststeps"][2]["request"]["verify"], True)
Beispiel #7
0
    def test_testsuite_parser(self):
        testcase_path = "tests/testsuites/create_users.yml"
        tests_mapping = loader.load_cases(testcase_path)

        parsed_testcases = parser.parse_tests(tests_mapping)
        self.assertEqual(len(parsed_testcases), 2)
        self.assertEqual(len(parsed_testcases[0]["teststeps"]), 2)

        testcase1 = parsed_testcases[0]["teststeps"][0]
        self.assertIn("setup and reset all (override)", testcase1["config"]["name"].raw_string)
        teststeps = testcase1["teststeps"]
        self.assertNotIn("testcase_def", testcase1)
        self.assertEqual(len(teststeps), 2)
        self.assertEqual(
            teststeps[0]["request"]["url"],
            "/api/get-token"
        )
Beispiel #8
0
 def test_validate(self):
     testcases = [{
         "config": {
             'name': "test validation"
         },
         "teststeps": [{
             "name":
             "test validation",
             "request": {
                 "url": "http://127.0.0.1:5000/",
                 "method": "GET",
             },
             "variables": {
                 "resp_status_code": 200,
                 "resp_body_success": True
             },
             "validate": [{
                 "eq": ["$resp_status_code", 200]
             }, {
                 "check": "$resp_status_code",
                 "comparator": "eq",
                 "expect": 200
             }, {
                 "check": "$resp_body_success",
                 "expect": True
             }, {
                 "check": "${is_status_code_200($resp_status_code)}",
                 "expect": True
             }]
         }]
     }]
     from tests.debugtalk import is_status_code_200
     tests_mapping = {
         "project_mapping": {
             "functions": {
                 "is_status_code_200": is_status_code_200
             }
         },
         "testcases": testcases
     }
     testcases = parser.parse_tests(tests_mapping)
     parsed_testcase = testcases[0]
     test_runner = runner.Runner(parsed_testcase["config"])
     teststep = parsed_testcase["teststeps"][0]
     test_runner.run_test(teststep)
Beispiel #9
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)
Beispiel #10
0
    def run_tests(self, tests_mapping):
        """ run testcase/testsuite data
        """
        capture_message("start to run tests")
        project_mapping = tests_mapping.get("project_mapping", {})
        self.project_working_directory = project_mapping.get("PWD", os.getcwd())

        if self.save_tests:
            utils.dump_logs(tests_mapping, project_mapping, "loaded")

        # parse tests
        self.exception_stage = "parse tests"
        parsed_testcases = parser.parse_tests(tests_mapping)
        parse_failed_testfiles = parser.get_parse_failed_testfiles()
        if parse_failed_testfiles:
            logger.log_warning("parse failures occurred ...")
            utils.dump_logs(parse_failed_testfiles, project_mapping, "parse_failed")

        if self.save_tests:
            utils.dump_logs(parsed_testcases, project_mapping, "parsed")

        # add tests to test suite
        self.exception_stage = "add tests to test suite"
        test_suite = self._add_tests(parsed_testcases)

        # run test suite
        self.exception_stage = "run test suite"
        results = self._run_suite(test_suite)

        # aggregate results
        self.exception_stage = "aggregate results"
        self._summary = self._aggregate(results)

        # generate html report
        self.exception_stage = "generate html report"
        report.stringify_summary(self._summary)

        if self.save_tests:
            utils.dump_logs(self._summary, project_mapping, "summary")

        return self._summary
Beispiel #11
0
    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."
        )
Beispiel #12
0
    def test_testcase_complex_run_suite(self):
        for testcase_path in [
            "tests/testcases/create_user.yml",
            "tests/testcases/create_user.v2.yml",
            "tests/testcases/create_user.json",
            "tests/testcases/create_user.v2.json"
        ]:
            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.assertEqual(
                results.records[0]["name"],
                "setup and reset all (override) for TESTCASE_CREATE_XXX."
            )
            self.assertEqual(
                results.records[1]["name"],
                "create user and check result."
            )