Example #1
0
    def test_get_status(self):
        """ Test the get_status function. """
        obs = pkgdblib.get_status(self.session)

        acl_status = [
            'Approved', 'Awaiting Review', 'Denied', 'Obsolete', 'Removed'
        ]
        self.assertEqual(obs['acl_status'], acl_status)

        pkg_status = ['Approved', 'Deprecated', 'Orphaned', 'Removed']
        self.assertEqual(obs['pkg_status'], pkg_status)

        clt_status = ['Active', 'EOL', 'Under Development']
        self.assertEqual(obs['clt_status'], clt_status)

        pkg_acl = ['approveacls', 'commit', 'watchbugzilla', 'watchcommits']
        self.assertEqual(obs['pkg_acl'], pkg_acl)

        obs = pkgdblib.get_status(self.session, 'acl_status')
        self.assertEqual(obs.keys(), ['acl_status'])
        self.assertEqual(obs['acl_status'], acl_status)

        obs = pkgdblib.get_status(self.session, ['acl_status', 'pkg_acl'])
        self.assertEqual(obs.keys(), ['pkg_acl', 'acl_status'])
        self.assertEqual(obs['pkg_acl'], pkg_acl)
        self.assertEqual(obs['acl_status'], acl_status)
Example #2
0
    def test_get_status(self):
        """ Test the get_status function. """
        obs = pkgdblib.get_status(self.session)

        acl_status = ['Approved', 'Awaiting Review', 'Denied', 'Obsolete',
                      'Removed']
        self.assertEqual(obs['acl_status'], acl_status)

        pkg_status = ['Approved', 'Deprecated', 'Orphaned', 'Removed']
        self.assertEqual(obs['pkg_status'], pkg_status)

        clt_status = ['Active', 'EOL', 'Under Development']
        self.assertEqual(obs['clt_status'], clt_status)

        pkg_acl = ['approveacls', 'commit', 'watchbugzilla', 'watchcommits']
        self.assertEqual(obs['pkg_acl'], pkg_acl)

        obs = pkgdblib.get_status(self.session, 'acl_status')
        self.assertEqual(obs.keys(), ['acl_status'])
        self.assertEqual(obs['acl_status'], acl_status)

        obs = pkgdblib.get_status(self.session, ['acl_status', 'pkg_acl'])
        self.assertEqual(obs.keys(), ['pkg_acl', 'acl_status'])
        self.assertEqual(obs['pkg_acl'], pkg_acl)
        self.assertEqual(obs['acl_status'], acl_status)
Example #3
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
Example #4
0
def api_collection_status(collection):
    ''' Update the status of collection.

    :arg collection_branchname: String of the collection branch name to change.
    :arg collection_status: String of the status to change the collection to

    '''
    httpcode = 200
    output = {}

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

    form = forms.CollectionStatusForm(
        csrf_enabled=False,
        clt_status=clt_status,
    )
    if form.validate_on_submit():
        clt_branchname = form.collection_branchname.data
        clt_status = form.collection_status.data

        if collection == clt_branchname:
            try:
                message = pkgdblib.update_collection_status(
                    SESSION,
                    clt_branchname,
                    clt_status,
                    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.message
                httpcode = 500
        else:
            output['output'] = 'notok'
            output['error'] = "You're trying to update the " \
                              "wrong collection"
            httpcode = 500
Example #5
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
Example #6
0
def api_collection_status(collection):
    '''
Update collection status
------------------------
    Update the status of collection.

    ::

        /api/collection/<collection branchname>/status/

    Accept POST query only.

    :arg collection_branchname: String of the collection branch name to change.
    :arg collection_status: String of the status to change the collection to

    Sample response:

    ::

        {
          "output": "ok",
          "messages": ["Collection updated to \"EOL\""]
        }

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

    '''
    httpcode = 200
    output = {}

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

    form = forms.CollectionStatusForm(
        csrf_enabled=False,
        clt_status=clt_status,
    )
    if form.validate_on_submit():
        clt_branchname = form.collection_branchname.data
        clt_status = form.collection_status.data

        if collection == clt_branchname:
            try:
                message = pkgdblib.update_collection_status(
                    SESSION,
                    clt_branchname,
                    clt_status,
                    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.message
                httpcode = 500
        else:
            output['output'] = 'notok'
            output['error'] = "You're trying to update the " \
                              "wrong collection"
            httpcode = 500