|
Packit Service |
21c75c |
# -*- coding: utf-8 -*-
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
# Copyright (C) 2012-2018 Red Hat, Inc.
|
|
Packit Service |
21c75c |
#
|
|
Packit Service |
21c75c |
# This copyrighted material is made available to anyone wishing to use,
|
|
Packit Service |
21c75c |
# modify, copy, or redistribute it subject to the terms and conditions of
|
|
Packit Service |
21c75c |
# the GNU General Public License v.2, or (at your option) any later version.
|
|
Packit Service |
21c75c |
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
Packit Service |
21c75c |
# ANY WARRANTY expressed or implied, including the implied warranties of
|
|
Packit Service |
21c75c |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
Packit Service |
21c75c |
# Public License for more details. You should have received a copy of the
|
|
Packit Service |
21c75c |
# GNU General Public License along with this program; if not, write to the
|
|
Packit Service |
21c75c |
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
21c75c |
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
|
|
Packit Service |
21c75c |
# source code or documentation are not subject to the GNU General Public
|
|
Packit Service |
21c75c |
# License and may only be used or replicated with the express permission of
|
|
Packit Service |
21c75c |
# Red Hat, Inc.
|
|
Packit Service |
21c75c |
#
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
from __future__ import absolute_import
|
|
Packit Service |
21c75c |
from __future__ import unicode_literals
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import itertools
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import libdnf.transaction
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import dnf.cli.commands
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import tests.support
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
class Remove(tests.support.ResultTestCase):
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
REPOS = []
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def setUp(self):
|
|
Packit Service |
21c75c |
super(Remove, self).setUp()
|
|
Packit Service |
21c75c |
self.allow_erasing = True
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_not_installed(self):
|
|
Packit Service |
21c75c |
""" Removing a not-installed package is a void operation. """
|
|
Packit Service |
21c75c |
with self.assertRaises(dnf.exceptions.PackagesNotInstalledError) as context:
|
|
Packit Service |
21c75c |
self.base.remove('mrkite')
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'mrkite')
|
|
Packit Service |
21c75c |
installed_pkgs = self.base.sack.query().installed().run()
|
|
Packit Service |
21c75c |
self.assertResult(self.base, installed_pkgs)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_remove(self):
|
|
Packit Service |
21c75c |
""" Simple remove. """
|
|
Packit Service |
21c75c |
self.base.remove("pepper")
|
|
Packit Service |
21c75c |
self.assertResult(self.base,
|
|
Packit Service |
21c75c |
tests.support.installed_but(self.base.sack, "pepper"))
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_remove_dependent(self):
|
|
Packit Service |
21c75c |
""" Remove a lib that some other package depends on. """
|
|
Packit Service |
21c75c |
self.base.remove("librita")
|
|
Packit Service |
21c75c |
# we should end up with nothing in this case:
|
|
Packit Service |
21c75c |
new_set = tests.support.installed_but(self.base.sack, "librita", "pepper")
|
|
Packit Service |
21c75c |
self.assertResult(self.base, new_set)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_remove_nevra(self):
|
|
Packit Service |
21c75c |
self.base.remove("pepper-20-0.x86_64")
|
|
Packit Service |
21c75c |
pepper = self.base.sack.query().installed().filter(name="pepper")
|
|
Packit Service |
21c75c |
(installed, removed) = self.installed_removed(self.base)
|
|
Packit Service |
21c75c |
self.assertLength(installed, 0)
|
|
Packit Service |
21c75c |
self.assertCountEqual(removed, pepper.run())
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_remove_glob(self):
|
|
Packit Service |
21c75c |
""" Test that weird input combinations with globs work. """
|
|
Packit Service |
21c75c |
ret = self.base.remove("*.i686")
|
|
Packit Service |
21c75c |
self.assertEqual(ret, 1)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_remove_provides(self):
|
|
Packit Service |
21c75c |
"""Remove uses provides too."""
|
|
Packit Service |
21c75c |
self.assertEqual(1, self.base.remove('parking'))
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_reponame(self):
|
|
Packit Service |
21c75c |
"""Test whether only packages from the repository are uninstalled."""
|
|
Packit Service |
21c75c |
pkg_subj = dnf.subject.Subject('librita.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
tsis = []
|
|
Packit Service |
21c75c |
for pkg in pkg_subj.get_best_query(self.base.sack).installed():
|
|
Packit Service |
21c75c |
pkg._force_swdb_repoid = "main"
|
|
Packit Service |
21c75c |
self.history.rpm.add_install(pkg)
|
|
Packit Service |
21c75c |
# tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
# dnf.transaction.INSTALL,
|
|
Packit Service |
21c75c |
# installed=pkg,
|
|
Packit Service |
21c75c |
# reason=libdnf.transaction.TransactionItemReason_USER
|
|
Packit Service |
21c75c |
# )
|
|
Packit Service |
21c75c |
# tsis.append(tsi)
|
|
Packit Service |
21c75c |
self._swdb_commit(tsis)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.base.remove('librita', 'main')
|
|
Packit Service |
21c75c |
self.assertResult(self.base, itertools.chain(
|
|
Packit Service |
21c75c |
self.base.sack.query().installed().filter(name__neq='librita'),
|
|
Packit Service |
21c75c |
dnf.subject.Subject('librita.i686').get_best_query(self.base.sack).installed())
|
|
Packit Service |
21c75c |
)
|