Add success test case

Most of the test cases ended in an error condition. This adds one
that does not.
This commit is contained in:
Ben Nemec 2018-09-13 20:00:47 +00:00
parent 3d2a3bc23f
commit c2972eb22d

View File

@ -56,6 +56,10 @@ class TestCommands(upgradecheck.UpgradeCommands):
) )
class SuccessCommands(TestCommands):
_upgrade_checks = ()
class TestUpgradeCommands(base.BaseTestCase): class TestUpgradeCommands(base.BaseTestCase):
def test_get_details(self): def test_get_details(self):
result = upgradecheck.UpgradeCheckResult( result = upgradecheck.UpgradeCheckResult(
@ -73,17 +77,21 @@ class TestUpgradeCommands(base.BaseTestCase):
class TestMain(base.BaseTestCase): class TestMain(base.BaseTestCase):
def test_main(self): def _run_test(self, func, expected):
mock_argv = ['test-status', 'upgrade', 'check'] mock_argv = ['test-status', 'upgrade', 'check']
with mock.patch.object(sys, 'argv', mock_argv, create=True): with mock.patch.object(sys, 'argv', mock_argv, create=True):
inst = TestCommands() result = upgradecheck.main(func)
result = upgradecheck.main(inst.check) self.assertEqual(expected, result)
self.assertEqual(upgradecheck.UpgradeCheckCode.FAILURE, result)
def test_main(self):
inst = TestCommands()
self._run_test(inst.check, upgradecheck.UpgradeCheckCode.FAILURE)
def test_main_exception(self): def test_main_exception(self):
def raises(): def raises():
raise Exception('test exception') raise Exception('test exception')
mock_argv = ['test-status', 'upgrade', 'check'] self._run_test(raises, 255)
with mock.patch.object(sys, 'argv', mock_argv, create=True):
result = upgradecheck.main(raises) def test_main_success(self):
self.assertEqual(255, result) inst = SuccessCommands()
self._run_test(inst.check, 0)