|
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 |
"""Tests of the history undo command."""
|
|
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 |
|
|
Packit Service |
21c75c |
from dnf.exceptions import PackagesNotAvailableError, PackagesNotInstalledError
|
|
Packit Service |
21c75c |
#from dnf.history import NEVRAOperations
|
|
Packit Service |
21c75c |
#from dnf.transaction import ERASE, DOWNGRADE, INSTALL, REINSTALL, UPGRADE
|
|
Packit Service |
21c75c |
#from dnf.transaction import TransactionItem
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
import tests.support
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
'''
|
|
Packit Service |
21c75c |
class BaseTest(tests.support.DnfBaseTestCase):
|
|
Packit Service |
21c75c |
"""Unit tests of dnf.Base."""
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
REPOS = ['main', 'updates']
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def assertEqualTransactionItems(self, one, two):
|
|
Packit Service |
21c75c |
self.assertEqual(one.op_type, two.op_type)
|
|
Packit Service |
21c75c |
self.assertEqual(str(one.installed), str(two.installed))
|
|
Packit Service |
21c75c |
self.assertEqual(str(one.erased), str(two.erased))
|
|
Packit Service |
21c75c |
self.assertEqual([str(i) for i in one.obsoleted], [str(i) for i in two.obsoleted])
|
|
Packit Service |
21c75c |
self.assertEqual(one.reason, two.reason)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_downgrade(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with a downgrade."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add(
|
|
Packit Service |
21c75c |
'Downgrade',
|
|
Packit Service |
21c75c |
'pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
'pepper-20-1.x86_64',
|
|
Packit Service |
21c75c |
('lotus-3-16.x86_64',)
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
transaction_it = iter(self.base.transaction)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
UPGRADE,
|
|
Packit Service |
21c75c |
installed='pepper-20-1.x86_64',
|
|
Packit Service |
21c75c |
erased='pepper-20-0.x86_64'
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
INSTALL,
|
|
Packit Service |
21c75c |
installed='lotus-3-16.x86_64',
|
|
Packit Service |
21c75c |
reason=libdnf.transaction.TransactionItemReason_USER
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertRaises(StopIteration, next, transaction_it)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_downgrade_notavailable(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with an unavailable downgrade."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Downgrade', 'pepper-20-0.x86_64', 'pepper-20-2.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base, self.assertRaises(PackagesNotAvailableError) as context:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'pepper-20-2.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_downgrade_notinstalled(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with a not installed downgrade."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Downgrade', 'lotus-3-0.x86_64', 'lotus-3-16.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base, self.assertRaises(PackagesNotInstalledError) as context:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'lotus-3-0.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_erase(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with an erase."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Erase', 'lotus-3-16.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
transaction_it = iter(self.base.transaction)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
INSTALL,
|
|
Packit Service |
21c75c |
installed='lotus-3-16.x86_64',
|
|
Packit Service |
21c75c |
reason=libdnf.transaction.TransactionItemReason_USER
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertRaises(StopIteration, next, transaction_it)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_erase_twoavailable(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with an erase available in two repos."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Erase', 'lotus-3-16.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
transaction_it = iter(self.base.transaction)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
INSTALL,
|
|
Packit Service |
21c75c |
installed='lotus-3-16.x86_64',
|
|
Packit Service |
21c75c |
reason=libdnf.transaction.TransactionItemReason_USER
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertRaises(StopIteration, next, transaction_it)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_erase_notavailable(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with an unavailable erase."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Erase', 'hole-1-1.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base, self.assertRaises(PackagesNotAvailableError) as context:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'hole-1-1.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_install(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with an install."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Install', 'pepper-20-0.x86_64', obsoleted_nevras=('lotus-3-16.x86_64',))
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
transaction_it = iter(self.base.transaction)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(ERASE, erased='pepper-20-0.x86_64')
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
INSTALL,
|
|
Packit Service |
21c75c |
installed='lotus-3-16.x86_64',
|
|
Packit Service |
21c75c |
reason=libdnf.transaction.TransactionItemReason_USER
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertRaises(StopIteration, next, transaction_it)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_install_notinstalled(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with a not installed install."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Install', 'mrkite-2-0.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base, self.assertRaises(PackagesNotInstalledError) as context:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'mrkite-2-0.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_reinstall(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with a reinstall."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add(
|
|
Packit Service |
21c75c |
'Reinstall',
|
|
Packit Service |
21c75c |
'pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
'pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
('hole-1-1.x86_64',)
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
transaction_it = iter(self.base.transaction)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
REINSTALL,
|
|
Packit Service |
21c75c |
installed='pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
erased='pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
obsoleted=('hole-1-1.x86_64',)
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertRaises(StopIteration, next, transaction_it)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_reinstall_notavailable(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with an unvailable reinstall."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Reinstall', 'mrkite-2-0.x86_64', 'mrkite-2-0.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base, self.assertRaises(PackagesNotInstalledError) as context:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'mrkite-2-0.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_reinstall_notinstalled(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with a not installed reinstall."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Reinstall', 'hole-1-1.x86_64', 'hole-1-1.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base, self.assertRaises(PackagesNotAvailableError) as context:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'hole-1-1.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_reinstall_notinstalled_obsoleted(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with a not installed obsoleted of a reinstall."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add(
|
|
Packit Service |
21c75c |
'Reinstall',
|
|
Packit Service |
21c75c |
'pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
'pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
('lotus-3-16.x86_64',)
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
transaction_it = iter(self.base.transaction)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
REINSTALL,
|
|
Packit Service |
21c75c |
installed='pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
erased='pepper-20-0.x86_64',
|
|
Packit Service |
21c75c |
obsoleted=()
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertRaises(StopIteration, next, transaction_it)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_update(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with an update."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Update', 'tour-5-0.noarch', 'tour-4.6-1.noarch', ('lotus-3-16.x86_64',))
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
transaction_it = iter(self.base.transaction)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
DOWNGRADE,
|
|
Packit Service |
21c75c |
installed='tour-4.6-1.noarch',
|
|
Packit Service |
21c75c |
erased='tour-5-0.noarch'
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
actual = next(transaction_it)
|
|
Packit Service |
21c75c |
expected = TransactionItem(
|
|
Packit Service |
21c75c |
INSTALL,
|
|
Packit Service |
21c75c |
installed='lotus-3-16.x86_64',
|
|
Packit Service |
21c75c |
reason=libdnf.transaction.TransactionItemReason_USER
|
|
Packit Service |
21c75c |
)
|
|
Packit Service |
21c75c |
self.assertEqualTransactionItems(actual, expected)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertRaises(StopIteration, next, transaction_it)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_update_notavailable(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with an unavailable update."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Update', 'tour-5-0.noarch', 'tour-4.6-2.noarch')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base, self.assertRaises(PackagesNotAvailableError) as context:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'tour-4.6-2.noarch')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
def test_history_undo_operations_update_notinstalled(self):
|
|
Packit Service |
21c75c |
"""Test history_undo_operations with a not installed update."""
|
|
Packit Service |
21c75c |
operations = NEVRAOperations()
|
|
Packit Service |
21c75c |
operations.add('Update', 'lotus-4-0.x86_64', 'lotus-3-16.x86_64')
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
with self.base, self.assertRaises(PackagesNotInstalledError) as context:
|
|
Packit Service |
21c75c |
self.base._history_undo_operations(operations, 0)
|
|
Packit Service |
21c75c |
|
|
Packit Service |
21c75c |
self.assertEqual(context.exception.pkg_spec, 'lotus-4-0.x86_64')
|
|
Packit Service |
21c75c |
'''
|