Skip to content

Commit

Permalink
Adjust dnfdaemon tests to new resolve() return value
Browse files Browse the repository at this point in the history
  • Loading branch information
m-blaha committed Mar 1, 2023
1 parent 0982829 commit 1dde5ad
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 68 deletions.
13 changes: 13 additions & 0 deletions test/dnf5daemon-server/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@

class InstallrootCase(unittest.TestCase):

def sanitize_transaction(self, resolved):
'''Prepare resolved transaction for assert'''
for object_type, action, reason, trans_item_attrs, pkg in resolved:
# id of package depends on order of the repos in the sack which varies
# between runs so we can't rely on the value
pkg.pop('id')
# also package size differs according to the builder
pkg.pop('package_size')
# TODO(mblaha): calculate correct replaces value
if "replaces" in trans_item_attrs:
trans_item_attrs.pop("replaces")


def setUp(self):
super(InstallrootCase, self).setUp()
self.maxDiff = None
Expand Down
31 changes: 19 additions & 12 deletions test/dnf5daemon-server/test_distro_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,40 +35,47 @@ def test_distro_sync_package(self):
self.iface_rpm.distro_sync(['one'], dbus.Dictionary({}, signature='sv'))

resolved, errors = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv'))

# id of package depends on order of the repos in the sack which varies
# between runs so we can't rely on the value
for action, pkg in resolved:
pkg.pop('id')
pkg.pop('package_size')
self.sanitize_transaction(resolved)

self.assertCountEqual(
resolved,
dbus.Array([
dbus.Struct((
dbus.UInt32(6), # action upgrade
dbus.Dictionary({ # package
dbus.String('Package'), # object type
dbus.String('Upgrade'), # action
dbus.String('External User'), # reason
dbus.Dictionary({ # transaction item attrs
}, signature=dbus.Signature('sv')),
dbus.Dictionary({ # package
dbus.String('evr'): dbus.String('2-1', variant_level=1),
dbus.String('name'): dbus.String('one', variant_level=1),
dbus.String('epoch'): dbus.String('0', variant_level=1),
dbus.String('version'): dbus.String('2', variant_level=1),
dbus.String('release'): dbus.String('1', variant_level=1),
dbus.String('arch'): dbus.String('noarch', variant_level=1),
dbus.String('install_size'): dbus.UInt64(0, variant_level=1),
dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1),
dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1),
dbus.String('from_repo_id'): dbus.String('', variant_level=1),
dbus.String('reason'): dbus.String('External User', variant_level=1),
}, signature=dbus.Signature('sv'))),
signature=None),
dbus.Struct((
dbus.UInt32(12), # action replaced
dbus.Dictionary({ # package
dbus.String('Package'), # object type
dbus.String('Replaced'), # action
dbus.String('External User'), # reason
dbus.Dictionary({ # transaction item attrs
}, signature=dbus.Signature('sv')),
dbus.Dictionary({ # package
dbus.String('evr'): dbus.String('1-1', variant_level=1),
dbus.String('name'): dbus.String('one', variant_level=1),
dbus.String('epoch'): dbus.String('0', variant_level=1),
dbus.String('version'): dbus.String('1', variant_level=1),
dbus.String('release'): dbus.String('1', variant_level=1),
dbus.String('arch'): dbus.String('noarch', variant_level=1),
dbus.String('install_size'): dbus.UInt64(0, variant_level=1),
dbus.String('repo'): dbus.String('@System', variant_level=1),
dbus.String('repo_id'): dbus.String('@System', variant_level=1),
dbus.String('from_repo_id'): dbus.String('<unknown>', variant_level=1),
dbus.String('reason'): dbus.String('External User', variant_level=1),
}, signature=dbus.Signature('sv'))),
signature=None)
], signature=dbus.Signature('(ua{sv})'))
Expand Down
31 changes: 19 additions & 12 deletions test/dnf5daemon-server/test_downgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,48 @@ def test_downgrade_package(self):
self.iface_rpm.downgrade(['one'], dbus.Dictionary({}, signature='sv'))

resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv'))

# id of package depends on order of the repos in the sack which varies
# between runs so we can't rely on the value
for action, pkg in resolved:
pkg.pop('id')
pkg.pop('package_size')
self.sanitize_transaction(resolved)

self.assertEqual(result, 0)
self.assertCountEqual(
resolved,
dbus.Array([
dbus.Struct((
dbus.UInt32(2), # action downgrade
dbus.Dictionary({ # package
dbus.String('Package'), # object type
dbus.String('Downgrade'), # action
dbus.String('External User'), # reason
dbus.Dictionary({ # transaction item attrs
}, signature=dbus.Signature('sv')),
dbus.Dictionary({ # package
dbus.String('evr'): dbus.String('1-1', variant_level=1),
dbus.String('name'): dbus.String('one', variant_level=1),
dbus.String('epoch'): dbus.String('0', variant_level=1),
dbus.String('version'): dbus.String('1', variant_level=1),
dbus.String('release'): dbus.String('1', variant_level=1),
dbus.String('arch'): dbus.String('noarch', variant_level=1),
dbus.String('install_size'): dbus.UInt64(0, variant_level=1),
dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1),
dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1),
dbus.String('from_repo_id'): dbus.String('', variant_level=1),
dbus.String('reason'): dbus.String('External User', variant_level=1),
}, signature=dbus.Signature('sv'))),
signature=None),
dbus.Struct((
dbus.UInt32(12), # action replaced
dbus.Dictionary({ # package
dbus.String('Package'), # object type
dbus.String('Replaced'), # action
dbus.String('External User'), # reason
dbus.Dictionary({ # transaction item attrs
}, signature=dbus.Signature('sv')),
dbus.Dictionary({ # package
dbus.String('evr'): dbus.String('2-1', variant_level=1),
dbus.String('name'): dbus.String('one', variant_level=1),
dbus.String('epoch'): dbus.String('0', variant_level=1),
dbus.String('version'): dbus.String('2', variant_level=1),
dbus.String('release'): dbus.String('1', variant_level=1),
dbus.String('arch'): dbus.String('noarch', variant_level=1),
dbus.String('install_size'): dbus.UInt64(0, variant_level=1),
dbus.String('repo'): dbus.String('@System', variant_level=1),
dbus.String('repo_id'): dbus.String('@System', variant_level=1),
dbus.String('from_repo_id'): dbus.String('<unknown>', variant_level=1),
dbus.String('reason'): dbus.String('External User', variant_level=1),
}, signature=dbus.Signature('sv'))),
signature=None)
], signature=dbus.Signature('(ua{sv})'))
Expand Down
21 changes: 11 additions & 10 deletions test/dnf5daemon-server/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,29 @@ def test_install_package(self):
self.iface_rpm.install(['one'], dbus.Dictionary({}, signature='sv'))

resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv'))

# id of package depends on order of the repos in the sack which varies
# between runs so we can't rely on the value
for action, pkg in resolved:
pkg.pop('id')
pkg.pop('package_size')
self.sanitize_transaction(resolved)

self.assertEqual(result, 0)
self.assertCountEqual(
resolved,
dbus.Array([
dbus.Struct((
dbus.UInt32(1), # action
dbus.Dictionary({ # package
dbus.String('Package'), # object type
dbus.String('Install'), # action
dbus.String('User'), # reason
dbus.Dictionary({ # transaction item attrs
}, signature=dbus.Signature('sv')),
dbus.Dictionary({ # package
dbus.String('arch'): dbus.String('noarch', variant_level=1),
dbus.String('epoch'): dbus.String('0', variant_level=1),
dbus.String('evr'): dbus.String('2-1', variant_level=1),
dbus.String('name'): dbus.String('one', variant_level=1),
dbus.String('install_size'): dbus.UInt64(0, variant_level=1),
dbus.String('release'): dbus.String('1', variant_level=1),
dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1),
dbus.String('version'): dbus.String('2', variant_level=1)
dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1),
dbus.String('version'): dbus.String('2', variant_level=1),
dbus.String('from_repo_id'): dbus.String('', variant_level=1),
dbus.String('reason'): dbus.String('None', variant_level=1),
}, signature=dbus.Signature('sv'))),
signature=None)
], signature=dbus.Signature('(ua{sv})'))
Expand Down
31 changes: 19 additions & 12 deletions test/dnf5daemon-server/test_reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,48 @@ def test_reinstall_package(self):
self.iface_rpm.reinstall(['one'], dbus.Dictionary({}, signature='sv'))

resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv'))

# id of package depends on order of the repos in the sack which varies
# between runs so we can't rely on the value
for action, pkg in resolved:
pkg.pop('id')
pkg.pop('package_size')
self.sanitize_transaction(resolved)

self.assertEqual(result, 0)
self.assertCountEqual(
resolved,
dbus.Array([
dbus.Struct((
dbus.UInt32(9), # action reinstall
dbus.Dictionary({ # package
dbus.String('Package'), # object type
dbus.String('Reinstall'), # action
dbus.String('External User'), # reason
dbus.Dictionary({ # transaction item attrs
}, signature=dbus.Signature('sv')),
dbus.Dictionary({ # package
dbus.String('evr'): dbus.String('1-1', variant_level=1),
dbus.String('name'): dbus.String('one', variant_level=1),
dbus.String('epoch'): dbus.String('0', variant_level=1),
dbus.String('version'): dbus.String('1', variant_level=1),
dbus.String('release'): dbus.String('1', variant_level=1),
dbus.String('arch'): dbus.String('noarch', variant_level=1),
dbus.String('install_size'): dbus.UInt64(0, variant_level=1),
dbus.String('repo'): dbus.String('rpm-repo1', variant_level=1),
dbus.String('repo_id'): dbus.String('rpm-repo1', variant_level=1),
dbus.String('from_repo_id'): dbus.String('', variant_level=1),
dbus.String('reason'): dbus.String('External User', variant_level=1),
}, signature=dbus.Signature('sv'))),
signature=None),
dbus.Struct((
dbus.UInt32(12), # action replaced
dbus.Dictionary({ # package
dbus.String('Package'), # object type
dbus.String('Replaced'), # action
dbus.String('External User'), # reason
dbus.Dictionary({ # transaction item attrs
}, signature=dbus.Signature('sv')),
dbus.Dictionary({ # package
dbus.String('evr'): dbus.String('1-1', variant_level=1),
dbus.String('name'): dbus.String('one', variant_level=1),
dbus.String('epoch'): dbus.String('0', variant_level=1),
dbus.String('version'): dbus.String('1', variant_level=1),
dbus.String('release'): dbus.String('1', variant_level=1),
dbus.String('arch'): dbus.String('noarch', variant_level=1),
dbus.String('install_size'): dbus.UInt64(0, variant_level=1),
dbus.String('repo'): dbus.String('@System', variant_level=1),
dbus.String('repo_id'): dbus.String('@System', variant_level=1),
dbus.String('from_repo_id'): dbus.String('<unknown>', variant_level=1),
dbus.String('reason'): dbus.String('External User', variant_level=1),
}, signature=dbus.Signature('sv'))),
signature=None)
], signature=dbus.Signature('(ua{sv})')),
Expand Down
21 changes: 11 additions & 10 deletions test/dnf5daemon-server/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,29 @@ def test_remove_package(self):
self.iface_rpm.remove(['one'], dbus.Dictionary({}, signature='sv'))

resolved, result = self.iface_goal.resolve(dbus.Dictionary({}, signature='sv'))

# id of package depends on order of the repos in the sack which varies
# between runs so we can't rely on the value
for action, pkg in resolved:
pkg.pop('id')
pkg.pop('package_size')
self.sanitize_transaction(resolved)

self.assertEqual(result, 0)
self.assertCountEqual(
resolved,
dbus.Array([
dbus.Struct((
dbus.UInt32(8), # action
dbus.Dictionary({ # package
dbus.String('Package'), # object type
dbus.String('Remove'), # action
dbus.String('User'), # reason
dbus.Dictionary({ # transaction item attrs
}, signature=dbus.Signature('sv')),
dbus.Dictionary({ # package
dbus.String('arch'): dbus.String('noarch', variant_level=1),
dbus.String('epoch'): dbus.String('0', variant_level=1),
dbus.String('evr'): dbus.String('1-1', variant_level=1),
dbus.String('name'): dbus.String('one', variant_level=1),
dbus.String('install_size'): dbus.UInt64(0, variant_level=1),
dbus.String('release'): dbus.String('1', variant_level=1),
dbus.String('repo'): dbus.String('@System', variant_level=1),
dbus.String('version'): dbus.String('1', variant_level=1)
dbus.String('repo_id'): dbus.String('@System', variant_level=1),
dbus.String('version'): dbus.String('1', variant_level=1),
dbus.String('from_repo_id'): dbus.String('<unknown>', variant_level=1),
dbus.String('reason'): dbus.String('External User', variant_level=1),
}, signature=dbus.Signature('sv'))),
signature=None)
], signature=dbus.Signature('(ua{sv})'))
Expand Down
Loading

0 comments on commit 1dde5ad

Please sign in to comment.