Mock away a method in unit tests that requires sudo

When helm repository refreshing was added to sysinv by
https://review.opendev.org/#/c/656745/
it meant that any unit tests that construct a conductor
manager would prompt for sudo password.

This commit mocks away the method that makes the sudo call.

Change-Id: If8118b32a03ac9bdaf4bcdbb6e034df38d7de1e2
Closes-Bug: #1829405
Signed-off-by: Al Bailey <Al.Bailey@windriver.com>
This commit is contained in:
Al Bailey 2019-05-16 11:18:36 -05:00
parent 368f730ff1
commit d70395104b
1 changed files with 9 additions and 0 deletions

View File

@ -44,6 +44,7 @@ import testtools
import eventlet
eventlet.monkey_patch(os=False)
import sysinv.common.utils
CONF = cfg.CONF
_DB_CACHE = None
@ -120,9 +121,13 @@ class TestingException(Exception):
class TestCase(testtools.TestCase):
"""Test case base class for all unit tests."""
helm_refresh_patcher = mock.patch.object(sysinv.common.utils, 'refresh_helm_repo_information')
def setUp(self):
"""Run before each test method to initialize test environment."""
super(TestCase, self).setUp()
self.mock_helm_refresh = self.helm_refresh_patcher.start()
self.dbapi = dbapi.get_instance()
test_timeout = os.environ.get('OS_TEST_TIMEOUT', 0)
@ -173,6 +178,10 @@ class TestCase(testtools.TestCase):
self.policy = self.useFixture(policy_fixture.PolicyFixture())
CONF.set_override('fatal_exception_format_errors', True)
def tearDown(self):
super(TestCase, self).tearDown()
self.helm_refresh_patcher.stop()
def _restore_obj_registry(self):
objects_base.SysinvObject._obj_classes = self._base_test_obj_backup