def test_track_packages(self): foo, bar = self.prepare_packages('foo', 'bar') foo.tracked = False bar.tracked = False self.db.commit() data.track_packages(self.session, self.collection, ['bar']) self.db.commit() self.assertFalse(foo.tracked) self.assertTrue(bar.tracked) self.assert_action_log("Package bar (collection f25): tracked set from False to True")
def execute(self, session, names, collection): if collection: collection = session.db.query(Collection)\ .filter_by(name=collection)\ .first() if not collection: sys.exit("Collection not found") try: data.track_packages(session, collection, names) except data.PackagesDontExist as e: sys.exit(str(e))
def add_packages(): """ Mark multiple packages as tracked. Optionally add them to a group. """ form = forms.AddPackagesForm() if request.method == 'POST': if not form.validate_or_flash(): return render_template("add-packages.html", form=form) names = set(form.packages.data) try: collection = [ c for c in g.collections if c.name == form.collection.data ][0] except IndexError: abort(404) try: added = data.track_packages(session, collection, names) except data.PackagesDontExist as e: db.rollback() flash_nak(str(e)) # frontend doesn't have Koji access, so it needs to rely on backend's polling flash_nak( dedent(""" If a package has been just created, it is possible that it hasn't been propagated to our database yet. In that case, please, try again later. """)) return render_template("add-packages.html", form=form) if form.group.data: namespace, name = PackageGroup.parse_name(form.group.data) group = db.query(PackageGroup)\ .filter_by(namespace=namespace, name=name)\ .first_or_404() if not group.editable: abort(400) data.set_group_content(session, group, names, append=True) flash_ack("Packages added: {}".format(','.join(p.name for p in added))) db.commit() return redirect(request.form.get('next') or url_for('frontpage')) return render_template("add-packages.html", form=form)
def add_packages(): """ Mark multiple packages as tracked. Optionally add them to a group. """ form = forms.AddPackagesForm() if request.method == 'POST': if not form.validate_or_flash(): return render_template("add-packages.html", form=form) names = set(form.packages.data) try: collection = [c for c in g.collections if c.name == form.collection.data][0] except IndexError: abort(404) try: added = data.track_packages(session, collection, names) except data.PackagesDontExist as e: db.rollback() flash_nak(str(e)) # frontend doesn't have Koji access, so it needs to rely on backend's polling flash_nak(dedent(""" If a package has been just created, it is possible that it hasn't been propagated to our database yet. In that case, please, try again later. """)) return render_template("add-packages.html", form=form) if form.group.data: namespace, name = PackageGroup.parse_name(form.group.data) group = db.query(PackageGroup)\ .filter_by(namespace=namespace, name=name)\ .first_or_404() if not group.editable: abort(400) data.set_group_content(session, group, names, append=True) flash_ack("Packages added: {}".format(','.join(p.name for p in added))) db.commit() return redirect(request.form.get('next') or url_for('frontpage')) return render_template("add-packages.html", form=form)
def test_track_packages_nonexistent(self): with self.assertRaises(data.PackagesDontExist): data.track_packages(self.session, self.collection, ['bar'])