diff --git a/repos/system_upgrade/common/libraries/tests/test_rpms.py b/repos/system_upgrade/common/libraries/tests/test_rpms.py index bb67d84ef6..bd29fb96e7 100644 --- a/repos/system_upgrade/common/libraries/tests/test_rpms.py +++ b/repos/system_upgrade/common/libraries/tests/test_rpms.py @@ -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 @@ -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)