def package_retire(package, collection): ''' Gives the possibility to orphan or take a package. ''' packagename = package package = None try: package_acl = pkgdblib.get_acl_package(SESSION, packagename) package = pkgdblib.search_package(SESSION, packagename, limit=1)[0] except NoResultFound: SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') except IndexError: flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') for acl in package_acl: if acl.collection.branchname == collection: if acl.point_of_contact == 'orphan': try: pkgdblib.update_pkg_status( session=SESSION, pkg_name=package.name, clt_name=acl.collection.branchname, status='Deprecated', user=flask.g.fas_user) flask.flash('This package has been retired on branch: %s' % collection) except pkgdblib.PkgdbException, err: flask.flash(err.message, 'error') break else: flask.flash('This package has not been orphaned on ' 'branch: %s' % collection)
def package_retire(package, collection): ''' Gives the possibility to orphan or take a package. ''' packagename = package package = None try: package_acl = pkgdblib.get_acl_package(SESSION, packagename) package = pkgdblib.search_package(SESSION, packagename, limit=1)[0] except (NoResultFound, IndexError): SESSION.rollback() flask.flash('No package of this name found.', 'errors') return flask.render_template('msg.html') for acl in package_acl: if acl.collection.branchname == collection: if acl.point_of_contact == 'orphan': try: pkgdblib.update_pkg_status( session=SESSION, pkg_name=package.name, pkg_branch=acl.collection.branchname, status='Retired', user=flask.g.fas_user ) flask.flash( 'This package has been retired on branch: %s' % collection) except pkgdblib.PkgdbException, err: flask.flash(err.message, 'error') SESSION.rollback() break else: flask.flash( 'This package has not been orphaned on ' 'branch: %s' % collection)
def api_package_undeprecate(): ''' Un-deprecate a list of packages. :arg packagenames: List of string of the packages name. :arg branches: List of string of the branches name in which these packages will be un-deprecated. ''' httpcode = 200 output = {} form = forms.DeprecatePackageForm(csrf_enabled=False) if form.validate_on_submit(): pkg_names = form.pkg_name.data.split(',') pkg_branchs = form.clt_name.data.split(',') try: for pkg_name, pkg_branch in itertools.product( pkg_names, pkg_branchs): message = pkgdblib.update_pkg_status( SESSION, pkg_name=pkg_name, clt_name=clt_name, status='Approved', 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
def api_package_undeprecate(): """ Un-deprecate a list of packages. :arg packagenames: List of string of the packages name. :arg branches: List of string of the branches name in which these packages will be un-deprecated. """ httpcode = 200 output = {} form = forms.DeprecatePackageForm(csrf_enabled=False) if form.validate_on_submit(): pkg_names = form.pkg_name.data.split(",") pkg_branchs = form.clt_name.data.split(",") try: for pkg_name, pkg_branch in itertools.product(pkg_names, pkg_branchs): message = pkgdblib.update_pkg_status( SESSION, pkg_name=pkg_name, clt_name=clt_name, status="Approved", 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
def test_update_pkg_status(self): """ Test the update_pkg_status function. """ create_package_acl(self.session) # Wrong package self.assertRaises( pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='test', clt_name='F-17', status='Deprecated', user=FakeFasUser(), ) self.session.rollback() # Wrong collection self.assertRaises( pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='F-16', status='Orphaned', user=FakeFasUser(), ) self.session.rollback() # User not allowed to deprecate the package on F-18 self.assertRaises( pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='F-18', status='Deprecated', user=FakeFasUser(), ) self.session.rollback() # Wrong status self.assertRaises( pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='F-18', status='Depreasdcated', user=FakeFasUser(), ) self.session.rollback() # User not allowed to change status to Allowed self.assertRaises( pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='F-18', status='Allowed', user=FakeFasUser(), ) self.session.rollback() # Admin can retire package pkgdblib.update_pkg_status(self.session, pkg_name='guake', clt_name='F-18', status='Deprecated', user=FakeFasUserAdmin()) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'orphan') self.assertEqual(pkg_acl[0].status, 'Deprecated') # User can orphan package pkgdblib.update_pkg_status(self.session, pkg_name='guake', clt_name='devel', status='Orphaned', user=FakeFasUser()) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'orphan') self.assertEqual(pkg_acl[0].status, 'Deprecated') self.assertEqual(pkg_acl[1].collection.branchname, 'devel') self.assertEqual(pkg_acl[1].package.name, 'guake') self.assertEqual(pkg_acl[1].point_of_contact, 'orphan') self.assertEqual(pkg_acl[1].status, 'Orphaned') # Admin must give a poc when un-orphan/un-retire a package self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='devel', status='Approved', user=FakeFasUserAdmin()) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'orphan') self.assertEqual(pkg_acl[0].status, 'Deprecated') self.assertEqual(pkg_acl[1].collection.branchname, 'devel') self.assertEqual(pkg_acl[1].package.name, 'guake') self.assertEqual(pkg_acl[1].point_of_contact, 'orphan') self.assertEqual(pkg_acl[1].status, 'Orphaned') # Admin can un-orphan package pkgdblib.update_pkg_status(self.session, pkg_name='guake', clt_name='devel', status='Approved', poc="pingou", user=FakeFasUserAdmin()) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'orphan') self.assertEqual(pkg_acl[0].status, 'Deprecated') self.assertEqual(pkg_acl[1].collection.branchname, 'devel') self.assertEqual(pkg_acl[1].package.name, 'guake') self.assertEqual(pkg_acl[1].point_of_contact, 'pingou') self.assertEqual(pkg_acl[1].status, 'Approved') # Admin can un-retire package pkgdblib.update_pkg_status(self.session, pkg_name='guake', clt_name='F-18', status='Approved', poc="pingou", user=FakeFasUserAdmin()) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'pingou') self.assertEqual(pkg_acl[0].status, 'Approved') self.assertEqual(pkg_acl[1].collection.branchname, 'devel') self.assertEqual(pkg_acl[1].package.name, 'guake') self.assertEqual(pkg_acl[1].point_of_contact, 'pingou') self.assertEqual(pkg_acl[1].status, 'Approved') # Not Admin and status is not Orphaned nor Deprecated self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='devel', status='Removed', user=FakeFasUser())
def test_update_pkg_status(self): """ Test the update_pkg_status function. """ create_package_acl(self.session) # Wrong package self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='test', clt_name='F-17', status='Deprecated', user=FakeFasUser(), ) self.session.rollback() # Wrong collection self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='F-16', status='Orphaned', user=FakeFasUser(), ) self.session.rollback() # User not allowed to deprecate the package on F-18 self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='F-18', status='Deprecated', user=FakeFasUser(), ) self.session.rollback() # Wrong status self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='F-18', status='Depreasdcated', user=FakeFasUser(), ) self.session.rollback() # User not allowed to change status to Allowed self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='F-18', status='Allowed', user=FakeFasUser(), ) self.session.rollback() # Admin can retire package pkgdblib.update_pkg_status(self.session, pkg_name='guake', clt_name='F-18', status='Deprecated', user=FakeFasUserAdmin() ) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'orphan') self.assertEqual(pkg_acl[0].status, 'Deprecated') # User can orphan package pkgdblib.update_pkg_status(self.session, pkg_name='guake', clt_name='devel', status='Orphaned', user=FakeFasUser() ) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'orphan') self.assertEqual(pkg_acl[0].status, 'Deprecated') self.assertEqual(pkg_acl[1].collection.branchname, 'devel') self.assertEqual(pkg_acl[1].package.name, 'guake') self.assertEqual(pkg_acl[1].point_of_contact, 'orphan') self.assertEqual(pkg_acl[1].status, 'Orphaned') # Admin must give a poc when un-orphan/un-retire a package self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='devel', status='Approved', user=FakeFasUserAdmin() ) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'orphan') self.assertEqual(pkg_acl[0].status, 'Deprecated') self.assertEqual(pkg_acl[1].collection.branchname, 'devel') self.assertEqual(pkg_acl[1].package.name, 'guake') self.assertEqual(pkg_acl[1].point_of_contact, 'orphan') self.assertEqual(pkg_acl[1].status, 'Orphaned') # Admin can un-orphan package pkgdblib.update_pkg_status(self.session, pkg_name='guake', clt_name='devel', status='Approved', poc="pingou", user=FakeFasUserAdmin() ) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'orphan') self.assertEqual(pkg_acl[0].status, 'Deprecated') self.assertEqual(pkg_acl[1].collection.branchname, 'devel') self.assertEqual(pkg_acl[1].package.name, 'guake') self.assertEqual(pkg_acl[1].point_of_contact, 'pingou') self.assertEqual(pkg_acl[1].status, 'Approved') # Admin can un-retire package pkgdblib.update_pkg_status(self.session, pkg_name='guake', clt_name='F-18', status='Approved', poc="pingou", user=FakeFasUserAdmin() ) pkg_acl = pkgdblib.get_acl_package(self.session, 'guake') self.assertEqual(pkg_acl[0].collection.branchname, 'F-18') self.assertEqual(pkg_acl[0].package.name, 'guake') self.assertEqual(pkg_acl[0].point_of_contact, 'pingou') self.assertEqual(pkg_acl[0].status, 'Approved') self.assertEqual(pkg_acl[1].collection.branchname, 'devel') self.assertEqual(pkg_acl[1].package.name, 'guake') self.assertEqual(pkg_acl[1].point_of_contact, 'pingou') self.assertEqual(pkg_acl[1].status, 'Approved') # Not Admin and status is not Orphaned nor Deprecated self.assertRaises(pkgdblib.PkgdbException, pkgdblib.update_pkg_status, self.session, pkg_name='guake', clt_name='devel', status='Removed', user=FakeFasUser() )