Exemplo n.º 1
0
def api_collection_new():
    ''' Create a new collection.

    :arg collection_name: String of the collection name to be created.
    :arg collection_version: String of the version of the collection.
    :arg collection_status: String of the name of the user owner of the
        collection.
    :arg collection_publishURLTemplate:
    :arg collection_pendingURLTemplate:
    :arg collection_summary:
    :arg collection_description:
    :arg collection_branchname:
    :arg collection_distTag:
    :arg collection_git_branch_name:

    '''
    httpcode = 200
    output = {}

    clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status']

    form = forms.AddCollectionForm(
        csrf_enabled=False,
        clt_status=clt_status,
    )
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = [message]
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = err
            httpcode = 500
Exemplo n.º 2
0
def collection_new():
    ''' Page to create a new collection. '''

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(clt_status=clt_status)
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash(message)
            return flask.redirect(flask.url_for('.list_collections'))
        # In theory we should never hit this
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            flask.flash(err.message, 'errors')
Exemplo n.º 3
0
    def test_add_collection(self):
        """ Test the add_collection function. """

        self.assertRaises(
            pkgdblib.PkgdbException,
            pkgdblib.add_collection,
            session=self.session,
            clt_name='Fedora',
            clt_version='19',
            clt_status='Active',
            clt_publishurl=None,
            clt_pendingurl=None,
            clt_summary='Fedora 19 release',
            clt_description='Fedora 19 collection',
            clt_branchname='F-19',
            clt_disttag='.fc19',
            clt_gitbranch='f19',
            user=FakeFasUser(),
        )
        self.session.rollback()

        pkgdblib.add_collection(
            self.session,
            clt_name='Fedora',
            clt_version='19',
            clt_status='Active',
            clt_publishurl=None,
            clt_pendingurl=None,
            clt_summary='Fedora 19 release',
            clt_description='Fedora 19 collection',
            clt_branchname='F-19',
            clt_disttag='.fc19',
            clt_gitbranch='f19',
            user=FakeFasUserAdmin(),
        )
        self.session.commit()
        collection = model.Collection.by_name(self.session, 'F-19')
        self.assertEqual(
            "Collection(u'Fedora', u'19', u'Active', u'admin', "
            "publishurltemplate=None, pendingurltemplate=None, "
            "summary=u'Fedora 19 release', "
            "description=u'Fedora 19 collection')", collection.__repr__())
Exemplo n.º 4
0
    def test_add_collection(self):
        """ Test the add_collection function. """

        self.assertRaises(pkgdblib.PkgdbException,
                          pkgdblib.add_collection,
                          session=self.session,
                          clt_name='Fedora',
                          clt_version='19',
                          clt_status='Active',
                          clt_publishurl=None,
                          clt_pendingurl=None,
                          clt_summary='Fedora 19 release',
                          clt_description='Fedora 19 collection',
                          clt_branchname='F-19',
                          clt_disttag='.fc19',
                          clt_gitbranch='f19',
                          user=FakeFasUser(),
                          )
        self.session.rollback()

        pkgdblib.add_collection(self.session,
                                clt_name='Fedora',
                                clt_version='19',
                                clt_status='Active',
                                clt_publishurl=None,
                                clt_pendingurl=None,
                                clt_summary='Fedora 19 release',
                                clt_description='Fedora 19 collection',
                                clt_branchname='F-19',
                                clt_disttag='.fc19',
                                clt_gitbranch='f19',
                                user=FakeFasUserAdmin(),
                                )
        self.session.commit()
        collection = model.Collection.by_name(self.session, 'F-19')
        self.assertEqual("Collection(u'Fedora', u'19', u'Active', u'admin', "
                         "publishurltemplate=None, pendingurltemplate=None, "
                         "summary=u'Fedora 19 release', "
                         "description=u'Fedora 19 collection')",
                         collection.__repr__())
Exemplo n.º 5
0
def collection_new():
    ''' Page to create a new collection. '''

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(clt_status=clt_status)
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash(message)
            return flask.redirect(flask.url_for('.list_collections'))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
Exemplo n.º 6
0
def collection_new():
    ''' Page to create a new collection. '''

    clt_status = pkgdb.lib.get_status(SESSION, 'clt_status')['clt_status']
    form = pkgdb.forms.AddCollectionForm(clt_status=clt_status)
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_publishurl = form.collection_publishURLTemplate.data
        clt_pendingurl = form.collection_pendingURLTemplate.data
        clt_summary = form.collection_summary.data
        clt_description = form.collection_description.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_publishurl=clt_publishurl,
                clt_pendingurl=clt_pendingurl,
                clt_summary=clt_summary,
                clt_description=clt_description,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            flask.flash(message)
            return flask.redirect(flask.url_for('.list_collections'))
        except pkgdblib.PkgdbException, err:
            SESSION.rollback()
            flask.flash(err.message, 'errors')
Exemplo n.º 7
0
def api_collection_new():
    '''
New collection
--------------
    Create a new collection.

    ::

        /api/collection/new/

    Accept POST queries only.

    :arg collection_name: String of the collection name to be created.
    :arg collection_version: String of the version of the collection.
    :arg collection_status: String of the name of the user owner of the
        collection.
    :arg collection_publishURLTemplate:
    :arg collection_pendingURLTemplate:
    :arg collection_summary: A summary description of the collection.
    :arg collection_description: A description of the collection.
    :arg collection_branchname: The short name of the collection (ie: F-18).
    :arg collection_distTag: The dist tag used by rpm for this collection
        (ie: .fc18).
    :arg collection_git_branch_name: The git branch name for this collection
        (ie: f18).

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["Collection F-20 created"]
        }

        {
          "output": "notok",
          "error": ["You are not allowed to create collections"]
        }

    '''
    httpcode = 200
    output = {}

    clt_status = pkgdblib.get_status(SESSION, 'clt_status')['clt_status']

    form = forms.AddCollectionForm(
        csrf_enabled=False,
        clt_status=clt_status,
    )
    if form.validate_on_submit():
        clt_name = form.collection_name.data
        clt_version = form.collection_version.data
        clt_status = form.collection_status.data
        clt_branchname = form.collection_branchname.data
        clt_disttag = form.collection_distTag.data
        clt_gitbranch = form.collection_git_branch_name.data

        try:
            message = pkgdblib.add_collection(
                SESSION,
                clt_name=clt_name,
                clt_version=clt_version,
                clt_status=clt_status,
                clt_branchname=clt_branchname,
                clt_disttag=clt_disttag,
                clt_gitbranch=clt_gitbranch,
                user=flask.g.fas_user,
            )
            SESSION.commit()
            output['output'] = 'ok'
            output['messages'] = [message]
        # Apparently we're pretty tight on checks and looks like we cannot
        # raise this exception in a normal situation
        except pkgdblib.PkgdbException, err:  # pragma: no cover
            SESSION.rollback()
            output['output'] = 'notok'
            output['error'] = err.message
            httpcode = 500