def test_unregister_system_fails(self): unregistration_cmd = "subscription-manager unregister" subscription.unregister_system() self.assertEqual(utils.run_subprocess.called, 1) self.assertEqual(utils.run_subprocess.cmd, unregistration_cmd) self.assertEqual(len(subscription.logging.getLogger.info_msgs), 1) self.assertEqual(len(subscription.logging.getLogger.warning_msgs), 1)
def test_unregister_system_keep_rhsm(self, monkeypatch, caplog, tool_opts): tool_opts.keep_rhsm = True subscription.unregister_system() assert "Skipping due to the use of --keep-rhsm." in caplog.records[ -1].message
def test_unregister_system_successfully(self): unregistration_cmd = "subscription-manager unregister" subscription.unregister_system() self.assertEqual(utils.run_subprocess.called, 1) self.assertEqual(utils.run_subprocess.cmd, unregistration_cmd) self.assertEqual(len(subscription.loggerinst.info_msgs), 1) self.assertEqual(len(subscription.loggerinst.task_msgs), 1) self.assertEqual(len(subscription.loggerinst.warning_msgs), 0)
def test_unregister_system_skipped(self, monkeypatch, caplog, tool_opts): tool_opts.keep_rhsm = True monkeypatch.setattr(pkghandler, "get_installed_pkg_objects", mock.Mock()) subscription.unregister_system() assert "Skipping due to the use of --keep-rhsm." in caplog.text pkghandler.get_installed_pkg_objects.assert_not_called()
def test_unregister_system_submgr_not_found(self, monkeypatch, caplog): rpm_command = ["rpm", "--quiet", "-q", "subscription-manager"] run_subprocess_mock = mock.Mock( side_effect=unit_tests.run_subprocess_side_effect((rpm_command, ("", 1)), )) monkeypatch.setattr(utils, "run_subprocess", value=run_subprocess_mock) subscription.unregister_system() assert "The subscription-manager package is not installed." in caplog.records[ -1].message
def test_unregister_system(self, output, ret_code, expected, monkeypatch, caplog): submgr_command = ("subscription-manager", "unregister") rpm_command = ("rpm", "--quiet", "-q", "subscription-manager") # Mock rpm command run_subprocess_mock = mock.Mock(side_effect=run_subprocess_side_effect( ( submgr_command, ( output, ret_code, ), ), (rpm_command, ("", 0)), ), ) monkeypatch.setattr(utils, "run_subprocess", value=run_subprocess_mock) subscription.unregister_system() assert expected in caplog.records[-1].message