def test_copr_logic_add_sends_create_gpg_key_action(self, f_users, f_mock_chroots, f_db): name = u"project_1" selected_chroots = [self.mc1.name] CoprsLogic.add(self.u1, name, selected_chroots) self.db.session.commit() actions = ActionsLogic.get_many(ActionTypeEnum("gen_gpg_key")).all() assert len(actions) == 1 data = json.loads(actions[0].data) assert data["username"] == self.u1.name assert data["projectname"] == name
def add_project(ownername): data = rename_fields(get_form_compatible_data()) form = forms.CoprFormFactory.create_form_cls()(data, meta={'csrf': False}) if not form.validate_on_submit(): raise BadRequest(form.errors) validate_chroots(get_input_dict(), MockChrootsLogic.get_multiple()) group = None if ownername[0] == "@": group = ComplexLogic.get_group_by_name_safe(ownername[1:]) try: copr = CoprsLogic.add( name=form.name.data.strip(), repos=" ".join(form.repos.data.split()), user=flask.g.user, selected_chroots=form.selected_chroots, description=form.description.data, instructions=form.instructions.data, check_for_duplicates=True, unlisted_on_hp=form.unlisted_on_hp.data, build_enable_net=form.enable_net.data, group=group, persistent=form.persistent.data, auto_prune=form.auto_prune.data, use_bootstrap_container=form.use_bootstrap_container.data, homepage=form.homepage.data, contact=form.contact.data, disable_createrepo=form.disable_createrepo.data, delete_after_days=form.delete_after_days.data, multilib=form.multilib.data, module_hotfixes=form.module_hotfixes.data, ) db.session.commit() except (DuplicateException, NonAdminCannotCreatePersistentProject, NonAdminCannotDisableAutoPrunning) as err: db.session.rollback() raise err return flask.jsonify(to_dict(copr))
def api_new_copr(username): """ Receive information from the user on how to create its new copr, check their validity and create the corresponding copr. :arg name: the name of the copr to add :arg chroots: a comma separated list of chroots to use :kwarg repos: a comma separated list of repository that this copr can use. :kwarg initial_pkgs: a comma separated list of initial packages to build in this new copr """ form = forms.CoprFormFactory.create_form_cls()(meta={'csrf': False}) infos = [] # are there any arguments in POST which our form doesn't know? infos.extend(validate_post_keys(form)) if form.validate_on_submit(): group = ComplexLogic.get_group_by_name_safe( username[1:]) if username[0] == "@" else None auto_prune = True if "auto_prune" in flask.request.form: auto_prune = form.auto_prune.data use_bootstrap_container = True if "use_bootstrap_container" in flask.request.form: use_bootstrap_container = form.use_bootstrap_container.data try: copr = CoprsLogic.add( name=form.name.data.strip(), repos=" ".join(form.repos.data.split()), user=flask.g.user, selected_chroots=form.selected_chroots, description=form.description.data, instructions=form.instructions.data, check_for_duplicates=True, disable_createrepo=form.disable_createrepo.data, unlisted_on_hp=form.unlisted_on_hp.data, build_enable_net=form.build_enable_net.data, group=group, persistent=form.persistent.data, auto_prune=auto_prune, use_bootstrap_container=use_bootstrap_container, ) infos.append("New project was successfully created.") if form.initial_pkgs.data: pkgs = form.initial_pkgs.data.split() for pkg in pkgs: builds_logic.BuildsLogic.add(user=flask.g.user, pkgs=pkg, srpm_url=pkg, copr=copr) infos.append("Initial packages were successfully " "submitted for building.") output = {"output": "ok", "message": "\n".join(infos)} db.session.commit() except (exceptions.DuplicateException, exceptions.NonAdminCannotCreatePersistentProject, exceptions.NonAdminCannotDisableAutoPrunning) as err: db.session.rollback() raise LegacyApiError(str(err)) else: errormsg = "Validation error\n" if form.errors: for field, emsgs in form.errors.items(): errormsg += "- {0}: {1}\n".format(field, "\n".join(emsgs)) errormsg = errormsg.replace('"', "'") raise LegacyApiError(errormsg) return flask.jsonify(output)
def api_new_copr(username): """ Receive information from the user on how to create its new copr, check their validity and create the corresponding copr. :arg name: the name of the copr to add :arg chroots: a comma separated list of chroots to use :kwarg repos: a comma separated list of repository that this copr can use. :kwarg initial_pkgs: a comma separated list of initial packages to build in this new copr """ form = forms.CoprFormFactory.create_form_cls()(csrf_enabled=False) # are there any arguments in POST which our form doesn't know? # TODO: don't use WTFform for parsing and validation here if any([ post_key not in form.__dict__.keys() for post_key in flask.request.form.keys() ]): raise LegacyApiError( "Unknown arguments passed (non-existing chroot probably)") elif form.validate_on_submit(): infos = [] try: copr = CoprsLogic.add( name=form.name.data.strip(), repos=" ".join(form.repos.data.split()), user=flask.g.user, selected_chroots=form.selected_chroots, description=form.description.data, instructions=form.instructions.data, check_for_duplicates=True, auto_createrepo=True, ) infos.append("New project was successfully created.") if form.initial_pkgs.data: pkgs = form.initial_pkgs.data.split() for pkg in pkgs: builds_logic.BuildsLogic.add(user=flask.g.user, pkgs=pkg, copr=copr) infos.append("Initial packages were successfully " "submitted for building.") output = {"output": "ok", "message": "\n".join(infos)} db.session.commit() except exceptions.DuplicateException as err: db.session.rollback() raise LegacyApiError(str(err)) else: errormsg = "Validation error\n" if form.errors: for field, emsgs in form.errors.items(): errormsg += "- {0}: {1}\n".format(field, "\n".join(emsgs)) errormsg = errormsg.replace('"', "'") raise LegacyApiError(errormsg) return flask.jsonify(output)
def api_new_copr(username): """ Receive information from the user on how to create its new copr, check their validity and create the corresponding copr. :arg name: the name of the copr to add :arg chroots: a comma separated list of chroots to use :kwarg repos: a comma separated list of repository that this copr can use. :kwarg initial_pkgs: a comma separated list of initial packages to build in this new copr """ form = forms.CoprFormFactory.create_form_cls()(csrf_enabled=False) # are there any arguments in POST which our form doesn't know? # TODO: don't use WTFform for parsing and validation here if any([post_key not in form.__dict__.keys() for post_key in flask.request.form.keys()]): raise LegacyApiError("Unknown arguments passed (non-existing chroot probably)") elif form.validate_on_submit(): infos = [] group = ComplexLogic.get_group_by_name_safe(username[1:]) if username[0] == "@" else None try: copr = CoprsLogic.add( name=form.name.data.strip(), repos=" ".join(form.repos.data.split()), user=flask.g.user, selected_chroots=form.selected_chroots, description=form.description.data, instructions=form.instructions.data, check_for_duplicates=False, auto_createrepo=True, group=group, ) infos.append("New project was successfully created.") if form.initial_pkgs.data: pkgs = form.initial_pkgs.data.split() for pkg in pkgs: builds_logic.BuildsLogic.add( user=flask.g.user, pkgs=pkg, copr=copr) infos.append("Initial packages were successfully " "submitted for building.") output = {"output": "ok", "message": "\n".join(infos)} db.session.commit() except exceptions.DuplicateException as err: db.session.rollback() raise LegacyApiError(str(err)) else: errormsg = "Validation error\n" if form.errors: for field, emsgs in form.errors.items(): errormsg += "- {0}: {1}\n".format(field, "\n".join(emsgs)) errormsg = errormsg.replace('"', "'") raise LegacyApiError(errormsg) return flask.jsonify(output)