def _post(self, *args, **kwargs):
        response = hresponse.HandlerResponse()
        group_id = kwargs.get("id", None)

        if group_id:
            response.status_code = 400
            response.reason = "To update a test group, use a PUT request"
        else:
            # TODO: double check the token with its lab name, we need to make
            # sure people are sending test reports with a token lab with the
            # correct lab name value.
            group_json = kwargs.get("json_obj", None)
            group_pop = group_json.pop
            group_get = group_json.get

            group_name = group_get(models.NAME_KEY)
            # TODO: move name validation into the initial json validation.
            if utils.valid_test_name(group_name):
                if group_get(models.LOG_KEY):
                    path_parts = (utils.BASE_PATH, group_get(models.JOB_KEY),
                                  group_get(models.GIT_BRANCH_KEY),
                                  group_get(models.KERNEL_KEY),
                                  group_get(models.ARCHITECTURE_KEY),
                                  group_get(models.DEFCONFIG_FULL_KEY),
                                  group_get(models.BUILD_ENVIRONMENT_KEY),
                                  group_get(models.LAB_NAME_KEY))
                    directory_path = os.path.join(*path_parts)

                    name = "-".join((group_get(models.NAME_KEY),
                                     group_get(models.BOARD_KEY)))
                    ext = 'txt'
                    filename = "{}.{}".format(name, ext)
                    kci_test._add_test_log(directory_path, filename,
                                           group_get(models.LOG_KEY))
                    group_json[models.BOOT_LOG_KEY] = filename

                dboptions = self.settings["dboptions"]
                (ret_val, group_id,
                 errors) = kci_test.import_and_save_kci_tests(
                     group_json, dboptions)

                if ret_val == 201:
                    response.status_code = ret_val
                    response.result = {models.ID_KEY: group_id}
                    response.reason = ("Test group '%s' created" % group_name)
                    response.headers = {
                        "Location": "/test/group/%s" % str(group_id)
                    }
                else:
                    response.status_code = ret_val
                    response.reason = ("Error saving test group '%s'" %
                                       group_name)
            else:
                response.status_code = 400
                response.reason = "Test group name not valid"

        return response
Esempio n. 2
0
    def _post(self, *args, **kwargs):
        response = hresponse.HandlerResponse()
        suite_id = kwargs.get("id", None)

        if suite_id:
            response.status_code = 400
            response.reason = "To update a test suite, use a PUT request"
        else:
            # TODO: double check the token with its lab name, we need to make
            # sure people are sending test reports with a token lab with the
            # correct lab name value. Check the boot handler.
            suite_json = kwargs.get("json_obj", None)
            suite_pop = suite_json.pop
            suite_get = suite_json.get

            # Remove the test_set and test_case from the JSON and pass them
            # as is.
            sets_list = suite_pop(models.TEST_SET_KEY, [])
            cases_list = suite_pop(models.TEST_CASE_KEY, [])

            suite_name = suite_get(models.NAME_KEY)
            # TODO: move name validation into the initial json validation.
            if utils.valid_test_name(suite_name):
                # Make sure the *_id values passed are valid.
                ret_val, error = self._check_references(
                    suite_get(models.BUILD_ID_KEY, None),
                    suite_get(models.JOB_ID_KEY, None),
                    suite_get(models.BOOT_ID_KEY, None)
                )

                if ret_val == 200:
                    test_suite = \
                        mtsuite.TestSuiteDocument.from_json(suite_json)
                    test_suite.created_on = datetime.datetime.now(
                        tz=bson.tz_util.utc)

                    ret_val, suite_id = utils.db.save(
                        self.db, test_suite, manipulate=True)

                    if ret_val == 201:
                        response.status_code = ret_val
                        response.result = {models.ID_KEY: suite_id}
                        response.reason = (
                            "Test suite '%s' created" %
                            suite_name)
                        response.headers = {
                            "Location": "/test/suite/%s" % str(suite_id)}

                        if sets_list:
                            if isinstance(sets_list, types.ListType):
                                response.status_code = 202
                                response.messages = (
                                    "Test sets will be parsed and imported")
                            else:
                                sets_list = []
                                response.errors = (
                                    "Test sets are not wrapped in a list; "
                                    "they will not be imported")

                        if cases_list:
                            if isinstance(cases_list, types.ListType):
                                response.status_code = 202
                                response.messages = (
                                    "Test cases will be parsed and imported")
                            else:
                                cases_list = []
                                response.errors = (
                                    "Test cases are not wrapped in a "
                                    "list; they will not be imported")

                        # Complete the update of the test suite and import
                        # everything else.
                        if all([cases_list, sets_list]):
                            self._import_suite_with_sets_and_cases(
                                suite_json,
                                suite_id, sets_list, cases_list, suite_name)
                        elif all([cases_list, not sets_list]):
                            self._import_suite_and_cases(
                                suite_json, suite_id, cases_list, suite_name)
                        elif all([not cases_list, sets_list]):
                            self._import_suite_and_sets(
                                suite_json, suite_id, sets_list, suite_name)
                        else:
                            # Just update the test suite document.
                            taskq.complete_test_suite_import.apply_async(
                                [
                                    suite_json,
                                    suite_id,
                                    suite_name,
                                    self.settings["dboptions"],
                                    self.settings["mailoptions"]
                                ]
                            )
                    else:
                        response.status_code = ret_val
                        response.reason = (
                            "Error saving test suite '%s'" % suite_name)
                else:
                    response.status_code = 400
                    response.reason = error
            else:
                response.status_code = 400
                response.reason = "Test suite name not valid"

        return response
Esempio n. 3
0
    def _post(self, *args, **kwargs):
        response = hresponse.HandlerResponse()
        group_id = kwargs.get("id", None)

        if group_id:
            response.status_code = 400
            response.reason = "To update a test group, use a PUT request"
        else:
            # TODO: double check the token with its lab name, we need to make
            # sure people are sending test reports with a token lab with the
            # correct lab name value.
            group_json = kwargs.get("json_obj", None)
            group_pop = group_json.pop
            group_get = group_json.get

            # Remove the test_cases from the JSON and pass it as is.
            cases_list = group_pop(models.TEST_CASES_KEY, [])

            group_name = group_get(models.NAME_KEY)
            # TODO: move name validation into the initial json validation.
            if utils.valid_test_name(group_name):
                # Make sure the *_id values passed are valid.
                ret_val, error = self._check_references(
                    group_get(models.BUILD_ID_KEY, None),
                    group_get(models.JOB_ID_KEY, None)
                )

                if ret_val == 200:
                    test_group = \
                        mtgroup.TestGroupDocument.from_json(group_json)
                    test_group.created_on = datetime.datetime.now(
                        tz=bson.tz_util.utc)

                    ret_val, group_id = utils.db.save(
                        self.db, test_group, manipulate=True)

                    if ret_val == 201:
                        response.status_code = ret_val
                        response.result = {models.ID_KEY: group_id}
                        response.reason = (
                            "Test group '%s' created" %
                            group_name)
                        response.headers = {
                            "Location": "/test/group/%s" % str(group_id)}

                        if cases_list:
                            if isinstance(cases_list, types.ListType):
                                response.status_code = 202
                                response.messages = (
                                    "Test cases will be parsed and imported")
                            else:
                                cases_list = []
                                response.errors = (
                                    "Test cases are not wrapped in a "
                                    "list; they will not be imported")

                        # Complete the update of the test group and import
                        # everything else.
                        if all([cases_list]):
                            self._import_group_and_cases(
                                group_json, group_id, cases_list, group_name)
                        else:
                            # Just update the test group document.
                            taskq.complete_test_group_import.apply_async(
                                [
                                    group_json,
                                    group_id,
                                    group_name,
                                    self.settings["dboptions"]
                                ]
                            )
                    else:
                        response.status_code = ret_val
                        response.reason = (
                            "Error saving test group '%s'" % group_name)
                else:
                    response.status_code = 400
                    response.reason = error
            else:
                response.status_code = 400
                response.reason = "Test group name not valid"

        return response
    def _post(self, *args, **kwargs):
        response = hresponse.HandlerResponse()
        group_id = kwargs.get("id", None)

        if group_id:
            response.status_code = 400
            response.reason = "To update a test group, use a PUT request"
        else:
            # TODO: double check the token with its lab name, we need to make
            # sure people are sending test reports with a token lab with the
            # correct lab name value.
            group_json = kwargs.get("json_obj", None)
            group_pop = group_json.pop
            group_get = group_json.get

            # Remove the test_cases from the JSON and pass it as is.
            cases_list = group_pop(models.TEST_CASES_KEY, [])

            group_name = group_get(models.NAME_KEY)
            # TODO: move name validation into the initial json validation.
            if utils.valid_test_name(group_name):
                # Make sure the *_id values passed are valid.
                ret_val, error = self._check_references(
                    group_get(models.BUILD_ID_KEY, None),
                    group_get(models.JOB_ID_KEY, None))

                if ret_val == 200:
                    test_group = \
                        mtgroup.TestGroupDocument.from_json(group_json)
                    test_group.created_on = datetime.datetime.now(
                        tz=bson.tz_util.utc)

                    ret_val, group_id = utils.db.save(self.db,
                                                      test_group,
                                                      manipulate=True)

                    if ret_val == 201:
                        response.status_code = ret_val
                        response.result = {models.ID_KEY: group_id}
                        response.reason = ("Test group '%s' created" %
                                           group_name)
                        response.headers = {
                            "Location": "/test/group/%s" % str(group_id)
                        }

                        if cases_list:
                            if isinstance(cases_list, types.ListType):
                                response.status_code = 202
                                response.messages = (
                                    "Test cases will be parsed and imported")
                            else:
                                cases_list = []
                                response.errors = (
                                    "Test cases are not wrapped in a "
                                    "list; they will not be imported")

                        # Complete the update of the test group and import
                        # everything else.
                        if all([cases_list]):
                            self._import_group_and_cases(
                                group_json, group_id, cases_list, group_name)
                        else:
                            # Just update the test group document.
                            taskq.complete_test_group_import.apply_async([
                                group_json, group_id, group_name,
                                self.settings["dboptions"]
                            ])
                    else:
                        response.status_code = ret_val
                        response.reason = ("Error saving test group '%s'" %
                                           group_name)
                else:
                    response.status_code = 400
                    response.reason = error
            else:
                response.status_code = 400
                response.reason = "Test group name not valid"

        return response
Esempio n. 5
0
    def test_valid_test_name(self):
        self.assertTrue(utils.valid_test_name("a-test-name"))
        self.assertTrue(utils.valid_test_name("a_test_name"))
        self.assertTrue(utils.valid_test_name("a.test.name"))
        self.assertTrue(utils.valid_test_name("a+test+name"))

        self.assertFalse(utils.valid_test_name("a-test/name"))
        self.assertFalse(utils.valid_test_name("a-test=name"))
        self.assertFalse(utils.valid_test_name("a-test~name"))
        self.assertFalse(utils.valid_test_name("a-test\"name"))
        self.assertFalse(utils.valid_test_name("a-test'name"))
        self.assertFalse(utils.valid_test_name("+a+test+name"))
        self.assertFalse(utils.valid_test_name("a+test+name+"))
        self.assertFalse(utils.valid_test_name(".a.test.name"))
        self.assertFalse(utils.valid_test_name("a.test.name."))
        self.assertFalse(utils.valid_test_name("-a.test.name"))
        self.assertFalse(utils.valid_test_name("a.test.name-"))
Esempio n. 6
0
    def test_valid_test_name(self):
        self.assertTrue(utils.valid_test_name("a-test-name"))
        self.assertTrue(utils.valid_test_name("a_test_name"))
        self.assertTrue(utils.valid_test_name("a.test.name"))
        self.assertTrue(utils.valid_test_name("a+test+name"))

        self.assertFalse(utils.valid_test_name("a-test/name"))
        self.assertFalse(utils.valid_test_name("a-test=name"))
        self.assertFalse(utils.valid_test_name("a-test~name"))
        self.assertFalse(utils.valid_test_name("a-test\"name"))
        self.assertFalse(utils.valid_test_name("a-test'name"))
        self.assertFalse(utils.valid_test_name("+a+test+name"))
        self.assertFalse(utils.valid_test_name("a+test+name+"))
        self.assertFalse(utils.valid_test_name(".a.test.name"))
        self.assertFalse(utils.valid_test_name("a.test.name."))
        self.assertFalse(utils.valid_test_name("-a.test.name"))
        self.assertFalse(utils.valid_test_name("a.test.name-"))