def test_check_warning(self): fake_checks = ( ('good', mock.Mock(return_value=status.UpgradeCheckResult( status.UpgradeCheckCode.SUCCESS))), ('warn', mock.Mock(return_value=status.UpgradeCheckResult( status.UpgradeCheckCode.WARNING, 'there might be a problem')) ), ) with mock.patch.object(self.cmd, '_upgrade_checks', fake_checks): self.assertEqual(status.UpgradeCheckCode.WARNING, self.cmd.check()) expected = """\ +-----------------------------------+ | Upgrade Check Results | +-----------------------------------+ | Check: good | | Result: Success | | Details: None | +-----------------------------------+ | Check: warn | | Result: Warning | | Details: there might be a problem | +-----------------------------------+ """ self.assertEqual(expected, self.output.getvalue())
def test_check_failure(self): # make the error details over 60 characters so we test the wrapping error_details = 'go back to bed' + '!' * 60 fake_checks = ( ('good', mock.Mock(return_value=status.UpgradeCheckResult( status.UpgradeCheckCode.SUCCESS ))), ('warn', mock.Mock(return_value=status.UpgradeCheckResult( status.UpgradeCheckCode.WARNING, 'there might be a problem' ))), ('fail', mock.Mock(return_value=status.UpgradeCheckResult( status.UpgradeCheckCode.FAILURE, error_details ))), ) with mock.patch.object(self.cmd, '_upgrade_checks', fake_checks): self.assertEqual(status.UpgradeCheckCode.FAILURE, self.cmd.check()) expected = """\ +-----------------------------------------------------------------------+ | Upgrade Check Results | +-----------------------------------------------------------------------+ | Check: good | | Result: Success | | Details: None | +-----------------------------------------------------------------------+ | Check: warn | | Result: Warning | | Details: there might be a problem | +-----------------------------------------------------------------------+ | Check: fail | | Result: Failure | | Details: go back to bed!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | | !!!!!!!!!!!!!! | +-----------------------------------------------------------------------+ """ self.assertEqual(expected, self.output.getvalue())
def test_check_success(self): fake_checks = (('good', mock.Mock(return_value=status.UpgradeCheckResult( status.UpgradeCheckCode.SUCCESS))), ) with mock.patch.object(self.cmd, '_upgrade_checks', fake_checks): self.assertEqual(status.UpgradeCheckCode.SUCCESS, self.cmd.check()) expected = """\ +-----------------------+ | Upgrade Check Results | +-----------------------+ | Check: good | | Result: Success | | Details: None | +-----------------------+ """ self.assertEqual(expected, self.output.getvalue())