|
Packit Service |
21c75c |
# -*- coding: utf-8 -*-
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
# Copyright (C) 2013-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 libdnf.transaction
|
|
Packit Service |
21c75c |
import rpm
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import dnf.goal
|
|
Packit Service |
21c75c |
import dnf.repo
|
|
Packit Service |
21c75c |
import dnf.transaction
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import tests.support
|
|
Packit Service |
21c75c |
from tests.support import mock
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
'''
|
|
Packit Service |
21c75c |
class TransactionItemTest(tests.support.DnfBaseTestCase):
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
REPOS = ['main', 'search']
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
@classmethod
|
|
Packit Service |
21c75c |
def setUpClass(cls):
|
|
Packit Service |
21c75c |
"""Prepare the class level fixture."""
|
|
Packit Service |
21c75c |
cls.newpkg = tests.support.MockPackage('new-1.0-1.x86_64')
|
|
Packit Service |
21c75c |
cls.oldpkg = tests.support.MockPackage('old-4.23-13.x86_64')
|
|
Packit Service |
21c75c |
cls.obspkg1 = tests.support.MockPackage('obs1-3.12-12.x86_64')
|
|
Packit Service |
21c75c |
cls.obspkg2 = tests.support.MockPackage('obs2-2.1-11.x86_64')
|
|
Packit Service |
21c75c |
cls.obspkg3 = tests.support.MockPackage('obs3-1.0-10.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_active_hist_state_erase(self):
|
|
Packit Service |
21c75c |
"""Test active_history_state with the erase op_type."""
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.ERASE, erased=self.oldpkg)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
history_state = tsi._active_history_state
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(history_state, 'Erase')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_active_hist_state_install(self):
|
|
Packit Service |
21c75c |
"""Test active_history_state with the install op_type."""
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.INSTALL, installed=self.newpkg,
|
|
Packit Service |
21c75c |
obsoleted=[self.obspkg1, self.obspkg2])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
history_state = tsi._active_history_state
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(history_state, 'Install')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_creating(self):
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.UPGRADE, self.newpkg, self.oldpkg,
|
|
Packit Service |
21c75c |
[self.obspkg1, self.obspkg2, self.obspkg3])
|
|
Packit Service |
21c75c |
self.assertEqual(tsi.installed, self.newpkg)
|
|
Packit Service |
21c75c |
self.assertEqual(tsi.erased, self.oldpkg)
|
|
Packit Service |
21c75c |
self.assertCountEqual(
|
|
Packit Service |
21c75c |
tsi.obsoleted, [self.obspkg1, self.obspkg2, self.obspkg3])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(dnf.transaction.ERASE,
|
|
Packit Service |
21c75c |
erased=self.oldpkg)
|
|
Packit Service |
21c75c |
self.assertEqual(tsi.installed, None)
|
|
Packit Service |
21c75c |
self.assertEqual(tsi.erased, self.oldpkg)
|
|
Packit Service |
21c75c |
self.assertCountEqual(tsi.obsoleted, ())
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_iterator_reinstall(self):
|
|
Packit Service |
21c75c |
"""Test self.history_iterator with the reinstall op_type."""
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.REINSTALL, self.newpkg, self.oldpkg,
|
|
Packit Service |
21c75c |
[self.obspkg1, self.obspkg2, self.obspkg3])
|
|
Packit Service |
21c75c |
self.assertCountEqual(
|
|
Packit Service |
21c75c |
tsi._history_iterator(),
|
|
Packit Service |
21c75c |
[(self.newpkg, 'Reinstall', True), (self.oldpkg, 'Reinstalled', False),
|
|
Packit Service |
21c75c |
(self.obspkg1, 'Obsoleted', False), (self.obspkg2, 'Obsoleted', False),
|
|
Packit Service |
21c75c |
(self.obspkg3, 'Obsoleted', False)])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_iterator_upgrade(self):
|
|
Packit Service |
21c75c |
"""Test self.history_iterator with the upgrade op_type."""
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.UPGRADE, self.newpkg, self.oldpkg,
|
|
Packit Service |
21c75c |
[self.obspkg1, self.obspkg2, self.obspkg3])
|
|
Packit Service |
21c75c |
self.assertCountEqual(
|
|
Packit Service |
21c75c |
tsi._history_iterator(),
|
|
Packit Service |
21c75c |
[(self.newpkg, 'Update', True), (self.oldpkg, 'Updated', False),
|
|
Packit Service |
21c75c |
(self.obspkg1, 'Obsoleted', False), (self.obspkg2, 'Obsoleted', False),
|
|
Packit Service |
21c75c |
(self.obspkg3, 'Obsoleted', False)])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_propagated_reason(self):
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.newpkg._force_swdb_repoid = "main"
|
|
Packit Service |
21c75c |
tsi1 = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.INSTALL,
|
|
Packit Service |
21c75c |
installed=self.newpkg,
|
|
Packit Service |
21c75c |
reason=libdnf.transaction.TransactionItemReason_DEPENDENCY
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.oldpkg._force_swdb_repoid = "main"
|
|
Packit Service |
21c75c |
tsi2 = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.INSTALL,
|
|
Packit Service |
21c75c |
installed=self.oldpkg,
|
|
Packit Service |
21c75c |
reason=libdnf.transaction.TransactionItemReason_DEPENDENCY
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
tsis = [tsi1, tsi2]
|
|
Packit Service |
21c75c |
self._swdb_commit(tsis)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
ionly = self.sack.query().filter(empty=True) # installonly_query
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.INSTALL,
|
|
Packit Service |
21c75c |
installed=self.newpkg,
|
|
Packit Service |
21c75c |
reason='user'
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
actual = tsi._propagated_reason(self.history, ionly)
|
|
Packit Service |
21c75c |
expected = libdnf.transaction.TransactionItemReason_USER
|
|
Packit Service |
21c75c |
self.assertEqual(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.UPGRADE,
|
|
Packit Service |
21c75c |
installed=self.newpkg,
|
|
Packit Service |
21c75c |
erased=self.oldpkg
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
actual = tsi._propagated_reason(self.history, ionly)
|
|
Packit Service |
21c75c |
expected = libdnf.transaction.TransactionItemReason_DEPENDENCY
|
|
Packit Service |
21c75c |
self.assertEqual(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.DOWNGRADE,
|
|
Packit Service |
21c75c |
installed=self.newpkg,
|
|
Packit Service |
21c75c |
erased=self.oldpkg
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
actual = tsi._propagated_reason(self.history, ionly)
|
|
Packit Service |
21c75c |
expected = libdnf.transaction.TransactionItemReason_DEPENDENCY
|
|
Packit Service |
21c75c |
self.assertEqual(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
# test the call can survive if no reason is known:
|
|
Packit Service |
21c75c |
self.history.reset_db()
|
|
Packit Service |
21c75c |
actual = tsi._propagated_reason(self.history, ionly)
|
|
Packit Service |
21c75c |
expected = libdnf.transaction.TransactionItemReason_UNKNOWN
|
|
Packit Service |
21c75c |
self.assertEqual(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_removes(self):
|
|
Packit Service |
21c75c |
tsi = dnf.transaction.TransactionItem(
|
|
Packit Service |
21c75c |
dnf.transaction.UPGRADE, self.newpkg, self.oldpkg,
|
|
Packit Service |
21c75c |
[self.obspkg1, self.obspkg2, self.obspkg3])
|
|
Packit Service |
21c75c |
self.assertCountEqual(
|
|
Packit Service |
21c75c |
tsi.removes(),
|
|
Packit Service |
21c75c |
[self.oldpkg, self.obspkg1, self.obspkg2, self.obspkg3])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
class TransactionTest(tests.support.TestCase):
|
|
Packit Service |
21c75c |
def setUp(self):
|
|
Packit Service |
21c75c |
self.ipkg = tests.support.MockPackage('inst-1.0-1.x86_64')
|
|
Packit Service |
21c75c |
self.upkg1 = tests.support.MockPackage('upg1-2.1-2.x86_64')
|
|
Packit Service |
21c75c |
self.upkg2 = tests.support.MockPackage('upg2-3.2-3.x86_64')
|
|
Packit Service |
21c75c |
self.dpkg = tests.support.MockPackage('down-4.3-4.x86_64')
|
|
Packit Service |
21c75c |
self.rpkg1 = tests.support.MockPackage('rem1-2.1-1.x86_64')
|
|
Packit Service |
21c75c |
self.rpkg2 = tests.support.MockPackage('rem2-3.2-2.x86_64')
|
|
Packit Service |
21c75c |
self.rpkg3 = tests.support.MockPackage('rem3-4.3-5.x86_64')
|
|
Packit Service |
21c75c |
self.opkg1 = tests.support.MockPackage('obs1-4.23-13.x86_64')
|
|
Packit Service |
21c75c |
self.opkg2 = tests.support.MockPackage('obs2-3.12-12.x86_64')
|
|
Packit Service |
21c75c |
self.opkg3 = tests.support.MockPackage('obs3-2.1-11.x86_64')
|
|
Packit Service |
21c75c |
self.opkg4 = tests.support.MockPackage('obs4-1.0-10.x86_64')
|
|
Packit Service |
21c75c |
self.trans = dnf.transaction.Transaction()
|
|
Packit Service |
21c75c |
self.trans.add_install(self.ipkg, [self.opkg1, self.opkg2, self.opkg3])
|
|
Packit Service |
21c75c |
self.trans.add_upgrade(self.upkg1, self.rpkg1, [self.opkg4])
|
|
Packit Service |
21c75c |
self.trans.add_upgrade(self.upkg2, self.rpkg2, [])
|
|
Packit Service |
21c75c |
self.trans.add_downgrade(self.dpkg, self.rpkg3, [])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_get_items(self):
|
|
Packit Service |
21c75c |
self.assertLength(self.trans._get_items(dnf.transaction.ERASE), 0)
|
|
Packit Service |
21c75c |
self.assertLength(self.trans._get_items(dnf.transaction.UPGRADE), 2)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_iter(self):
|
|
Packit Service |
21c75c |
self.assertLength(list(self.trans), 4)
|
|
Packit Service |
21c75c |
self.assertIsInstance(next(iter(self.trans)),
|
|
Packit Service |
21c75c |
dnf.transaction.TransactionItem)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_length(self):
|
|
Packit Service |
21c75c |
self.assertLength(self.trans, 4)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_sets(self):
|
|
Packit Service |
21c75c |
self.assertCountEqual(
|
|
Packit Service |
21c75c |
self.trans.install_set,
|
|
Packit Service |
21c75c |
[self.ipkg, self.upkg1, self.upkg2, self.dpkg])
|
|
Packit Service |
21c75c |
self.assertCountEqual(
|
|
Packit Service |
21c75c |
self.trans.remove_set,
|
|
Packit Service |
21c75c |
[self.opkg1, self.opkg2, self.opkg3, self.opkg4,
|
|
Packit Service |
21c75c |
self.rpkg1, self.rpkg2, self.rpkg3])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_total_package_count(self):
|
|
Packit Service |
21c75c |
self.assertEqual(self.trans._total_package_count(), 11)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
class RPMLimitationsTest(tests.support.TestCase):
|
|
Packit Service |
21c75c |
def test_rpm_limitations(self):
|
|
Packit Service |
21c75c |
ts = dnf.transaction.Transaction()
|
|
Packit Service |
21c75c |
pkg = tests.support.MockPackage('anyway-2-0.src')
|
|
Packit Service |
21c75c |
ts.add_install(pkg, [])
|
|
Packit Service |
21c75c |
msg = ts._rpm_limitations()
|
|
Packit Service |
21c75c |
self.assertIsNot(msg, None)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
class PopulateTSTest(tests.support.TestCase):
|
|
Packit Service |
21c75c |
@staticmethod
|
|
Packit Service |
21c75c |
def test_populate_rpm_ts():
|
|
Packit Service |
21c75c |
ts = dnf.transaction.Transaction()
|
|
Packit Service |
21c75c |
conf = tests.support.FakeConf(cachedir='/tmp')
|
|
Packit Service |
21c75c |
repo = dnf.repo.Repo('r', conf)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
inst = tests.support.MockPackage("ago-20.0-1.x86_64.fc69", repo)
|
|
Packit Service |
21c75c |
upg = tests.support.MockPackage("billy-1.2-1.x86_64.fc69", repo)
|
|
Packit Service |
21c75c |
old = tests.support.MockPackage("billy-1.1-1.x86_64.fc69", repo)
|
|
Packit Service |
21c75c |
ts.add_install(inst, [])
|
|
Packit Service |
21c75c |
ts.add_upgrade(upg, old, [])
|
|
Packit Service |
21c75c |
rpm_ts = ts._populate_rpm_ts(mock.Mock())
|
|
Packit Service |
21c75c |
rpm_ts.assert_has_calls([mock.call.addInstall(None, ts._tsis[0], 'i'),
|
|
Packit Service |
21c75c |
mock.call.addInstall(None, ts._tsis[1], 'u')])
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
class RPMProbFilters(tests.support.DnfBaseTestCase):
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
REPOS = ['main', 'search']
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
@mock.patch('dnf.rpm.transaction.TransactionWrapper')
|
|
Packit Service |
21c75c |
def test_filters_install(self, _mock_ts):
|
|
Packit Service |
21c75c |
self.base.install("lotus")
|
|
Packit Service |
21c75c |
ts = self.base._ts
|
|
Packit Service |
21c75c |
ts.setProbFilter.assert_called_with(rpm.RPMPROB_FILTER_OLDPACKAGE)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
@mock.patch('dnf.rpm.transaction.TransactionWrapper')
|
|
Packit Service |
21c75c |
def test_filters_downgrade(self, _ts):
|
|
Packit Service |
21c75c |
self.base.downgrade("tour")
|
|
Packit Service |
21c75c |
ts = self.base._ts
|
|
Packit Service |
21c75c |
ts.setProbFilter.assert_called_with(rpm.RPMPROB_FILTER_OLDPACKAGE)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
@mock.patch('dnf.rpm.transaction.TransactionWrapper')
|
|
Packit Service |
21c75c |
def test_filters_reinstall(self, _ts):
|
|
Packit Service |
21c75c |
self.base.reinstall("librita")
|
|
Packit Service |
21c75c |
expected = rpm.RPMPROB_FILTER_OLDPACKAGE
|
|
Packit Service |
21c75c |
self.base._ts.setProbFilter.assert_called_with(expected)
|
|
Packit Service |
21c75c |
'''
|