Skip to content

Commit

Permalink
Fix for unit tests in package_updates (#1010)
Browse files Browse the repository at this point in the history
  • Loading branch information
pr-watson authored Dec 8, 2023
1 parent 7c51cf6 commit 039ded7
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,43 @@ def test_check_package_updates_not_up_to_date_skip(pretend_os, monkeypatch, pack
)
expected = set(
(
actions.ActionMessage(
level="WARNING",
id="OUTDATED_PACKAGE_MESSAGE",
title="Outdated packages detected",
description="Please refer to the diagnosis for further information",
diagnosis=diagnosis,
),
actions.ActionMessage(
level="WARNING",
id="SKIP_OUTDATED_PACKAGE_CHECK",
title="Skip package not up to date check",
description=(
"Detected 'CONVERT2RHEL_OUTDATED_PACKAGE_CHECK' environment variable, we will skip "
"Detected 'CONVERT2RHEL_OUTDATED_PACKAGE_CHECK_SKIP' environment variable, we will skip "
"the package up-to-date check.\n"
"Beware, this could leave your system in a broken state."
),
),
actions.ActionMessage(
level="WARNING",
id="OUTDATED_PACKAGE_MESSAGE",
title="Outdated packages detected",
description="Please refer to the diagnosis for further information",
diagnosis=diagnosis,
remediation="Run yum update to update all the packages on the system.",
),
)
)
package_updates_action.run()
assert expected.issuperset(package_updates_action.messages)
assert expected.issubset(package_updates_action.messages)


@centos8
def test_check_package_updates_with_repoerror(pretend_os, monkeypatch, caplog, package_updates_action):
get_total_packages_to_update_mock = mock.Mock(side_effect=pkgmanager.RepoError("This is an error"))
monkeypatch.setattr(package_updates, "get_total_packages_to_update", value=get_total_packages_to_update_mock)
diagnosis = (
"There was an error while checking whether the installed packages are up-to-date. Having an updated system is"
" an important prerequisite for a successful conversion. Consider verifyng the system is up to date manually"
" before proceeding with the conversion. This is an error"
"There was an error while checking whether the installed packages are up-to-date."
" Having an updated system is an important prerequisite for a successful conversion."
" Consider verifying the system is up to date manually before proceeding with the conversion."
" This is an error"
)
package_updates_action.run()

unit_tests.assert_actions_result(
package_updates_action,
level="OVERRIDABLE",
Expand All @@ -154,24 +160,23 @@ def test_check_package_updates_with_repoerror(pretend_os, monkeypatch, caplog, p
diagnosis=diagnosis,
remediation="If you wish to ignore this message, set the environment variable "
"'CONVERT2RHEL_PACKAGE_UP_TO_DATE_CHECK_SKIP' to 1.",
variables={},
)

assert diagnosis in caplog.records[-1].message


@centos8
def test_check_package_updates_with_repoerror_skip(pretend_os, monkeypatch, caplog, package_updates_action):
get_total_packages_to_update_mock = mock.Mock(side_effect=pkgmanager.RepoError("This is an error"))
monkeypatch.setattr(package_updates, "get_total_packages_to_update", value=get_total_packages_to_update_mock)
monkeypatch.setattr(package_updates, "get_total_packages_to_update", value=get_total_packages_to_update_mock)
monkeypatch.setattr(
os,
"environ",
{"CONVERT2RHEL_PACKAGE_UP_TO_DATE_CHECK_SKIP": 1},
)
diagnosis = (
"There was an error while checking whether the installed packages are up-to-date. Having an updated system is"
" an important prerequisite for a successful conversion. Consider verifyng the system is up to date manually"
" an important prerequisite for a successful conversion. Consider verifying the system is up to date manually"
" before proceeding with the conversion. This is an error"
)
expected = set(
Expand All @@ -183,6 +188,7 @@ def test_check_package_updates_with_repoerror_skip(pretend_os, monkeypatch, capl
description="Please refer to the diagnosis for further information",
diagnosis=diagnosis,
remediation=None,
variables={},
),
actions.ActionMessage(
level="WARNING",
Expand All @@ -193,12 +199,14 @@ def test_check_package_updates_with_repoerror_skip(pretend_os, monkeypatch, capl
"the package up-to-date check.\n"
"Beware, this could leave your system in a broken state."
),
diagnosis=None,
remediation=None,
variables={},
),
)
)

package_updates_action.run()

assert diagnosis in caplog.records[-1].message
assert expected.issuperset(package_updates_action.messages)
assert expected.issubset(package_updates_action.messages)
Expand Down

0 comments on commit 039ded7

Please sign in to comment.