Skip to content

Commit

Permalink
Update unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
abadger committed Jan 8, 2024
1 parent 894fb46 commit 5da27e8
Showing 1 changed file with 58 additions and 24 deletions.
82 changes: 58 additions & 24 deletions repos/system_upgrade/common/libraries/tests/test_rpms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from leapp.libraries.common.rpms import _parse_config_modification, get_leapp_packages
from leapp.libraries.common.rpms import _parse_config_modification, get_leapp_packages, get_leapp_dep_packages
from leapp.libraries.common.testutils import CurrentActorMocked
from leapp.libraries.stdlib import api

Expand Down Expand Up @@ -36,28 +36,62 @@ def test_parse_config_modification():
assert _parse_config_modification(data, "/etc/ssh/sshd_config")


@pytest.mark.parametrize('major_version,component,include_deps,result', [
(None, None, False, ['leapp', 'python3-leapp', 'leapp-upgrade-el8toel9', 'snactor']),
(None, None, True, ['leapp', 'leapp-deps', 'python3-leapp', 'leapp-upgrade-el8toel9',
'leapp-upgrade-el8toel9-deps', 'snactor']),
('7', None, False, ['leapp', 'python2-leapp', 'leapp-upgrade-el7toel8', 'snactor']),
(['7', '8'], None, False, ['leapp', 'python2-leapp', 'leapp-upgrade-el7toel8',
'python3-leapp', 'leapp-upgrade-el8toel9', 'snactor']),
('nosuchversion', None, False,
(ValueError, r"major_version nosuchversion is unknown, available choices are \['7', '8']")),
('8', 'framework', False, ['leapp', 'python3-leapp']),
('8', 'framework', True, ['leapp', 'python3-leapp', 'leapp-deps']),
('8', 'nosuchcomponent', True,
(ValueError,
r"component nosuchcomponent is unknown, available choices are \['cockpit', 'framework', 'repository', 'tools']")),
@pytest.mark.parametrize('major_version,component,result', [
(None, None, ['leapp', 'python3-leapp', 'leapp-upgrade-el8toel9', 'snactor']),
('7', None, ['leapp', 'python2-leapp', 'leapp-upgrade-el7toel8', 'snactor']),
(['7', '8'], None, ['leapp', 'python2-leapp', 'leapp-upgrade-el7toel8',
'python3-leapp', 'leapp-upgrade-el8toel9', 'snactor']),
('8', 'framework', ['leapp', 'python3-leapp']),
])
def test_get_leapp_packages(major_version, component, include_deps, result, monkeypatch):
def test_get_leapp_packages(major_version, component, result, monkeypatch):
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='8.9', dst_ver='9.3'))

kwargs = {}
if major_version:
kwargs["major_version"] = major_version
if component:
kwargs["component"] = component

assert set(get_leapp_packages(** kwargs)) == set(result)


@pytest.mark.parametrize('major_version,component,result', [
('8', 'nosuchcomponent',
(ValueError,
r"component nosuchcomponent is unknown, available choices are \['cockpit', 'framework', 'repository', 'tools']")
),
('nosuchversion', "framework",
(ValueError, r"major_version nosuchversion is unknown, available choices are \['7', '8']")),
('nosuchversion', False,
(ValueError, r"At least one component must be specified when calling this function,"
r" available choices are \['cockpit', 'framework', 'repository', 'tools']")),
])
def test_get_leapp_packages_errors(major_version, component, result, monkeypatch):
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='8.9', dst_ver='9.3'))

kwargs = {}
if major_version:
kwargs["major_version"] = major_version
if component is not None:
kwargs["component"] = component

exc_type, exc_msg = result
with pytest.raises(exc_type, match=exc_msg):
get_leapp_packages(**kwargs)


@pytest.mark.parametrize('major_version,component,result', [
(None, None, ['leapp-deps', 'leapp-upgrade-el8toel9-deps']),
('8', 'framework', ['leapp-deps']),
('7', 'tools', []),
])
def test_get_leapp_dep_packages(major_version, component, result, monkeypatch):
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='8.9', dst_ver='9.3'))
if isinstance(result, list):
assert set(get_leapp_packages(major_version, component, include_deps)) == set(result)
else:
# expect an exception tuple
exc_type, exc_msg = result
with pytest.raises(exc_type) as err:
get_leapp_packages(major_version, component, include_deps)
assert err.match(exc_msg)

kwargs = {}
if major_version:
kwargs["major_version"] = major_version
if component:
kwargs["component"] = component

assert frozenset(get_leapp_dep_packages(**kwargs)) == frozenset(result)

0 comments on commit 5da27e8

Please sign in to comment.