Tests: Don't write bash-completion cache files

Mock out writing of bash-completion cache files
during unit tests.

Related-Bug: #1817782

Change-Id: I944862c30fb4684dd034eba6953e9302d2d22439
This commit is contained in:
Eric Harney 2019-02-26 14:13:52 -05:00
parent 7ee806f218
commit a39805c6f4
6 changed files with 33 additions and 0 deletions

View File

@ -91,6 +91,8 @@ class Manager(common_base.HookableMixin):
except KeyError:
pass
# FIXME(eharney): This is probably a bug - we should only call
# completion_cache for the shell, not here.
with self.completion_cache('human_id', obj_class, mode="w"):
with self.completion_cache('uuid', obj_class, mode="w"):
items_new = [obj_class(self, res, loaded=True)

View File

@ -59,6 +59,8 @@ class ShellTest(utils.TestCase):
self.useFixture(fixtures.EnvironmentVariable(var,
self.FAKE_ENV[var]))
self.mock_completion()
def shell(self, argstr):
orig = sys.stdout
try:
@ -294,6 +296,11 @@ class ShellTest(utils.TestCase):
class CinderClientArgumentParserTest(utils.TestCase):
def setUp(self):
super(CinderClientArgumentParserTest, self).setUp()
self.mock_completion()
def test_ambiguity_solved_for_one_visible_argument(self):
parser = shell.CinderClientArgumentParser(add_help=False)
parser.add_argument('--test-parameter',
@ -336,6 +343,10 @@ class CinderClientArgumentParserTest(utils.TestCase):
class TestLoadVersionedActions(utils.TestCase):
def setUp(self):
super(TestLoadVersionedActions, self).setUp()
self.mock_completion()
def test_load_versioned_actions(self):
parser = cinderclient.shell.CinderClientArgumentParser()

View File

@ -15,6 +15,7 @@ import json
import os
import fixtures
import mock
import requests
from requests_mock.contrib import fixture as requests_mock_fixture
import six
@ -40,6 +41,9 @@ class TestCase(testtools.TestCase):
stderr = self.useFixture(fixtures.StringStream('stderr')).stream
self.useFixture(fixtures.MonkeyPatch('sys.stderr', stderr))
# FIXME(eharney) - this should only be needed for shell tests
self.mock_completion()
def _assert_request_id(self, obj, count=1):
self.assertTrue(hasattr(obj, 'request_ids'))
self.assertEqual(REQUEST_ID * count, obj.request_ids)
@ -49,6 +53,16 @@ class TestCase(testtools.TestCase):
return self.shell.cs.assert_called_anytime(method, url, body,
partial_body)
def mock_completion(self):
patcher = mock.patch(
'cinderclient.base.Manager.write_to_completion_cache')
patcher.start()
self.addCleanup(patcher.stop)
patcher = mock.patch('cinderclient.base.Manager.completion_cache')
patcher.start()
self.addCleanup(patcher.stop)
class FixturedTestCase(TestCase):

View File

@ -48,6 +48,8 @@ class ShellTest(utils.TestCase):
self.useFixture(fixtures.EnvironmentVariable(var,
self.FAKE_ENV[var]))
self.mock_completion()
self.shell = shell.OpenStackCinderShell()
# HACK(bcwaldon): replace this when we start using stubs

View File

@ -51,6 +51,8 @@ class ShellTest(utils.TestCase):
self.useFixture(fixtures.EnvironmentVariable(var,
self.FAKE_ENV[var]))
self.mock_completion()
self.shell = shell.OpenStackCinderShell()
self.requests = self.useFixture(requests_mock_fixture.Fixture())

View File

@ -79,6 +79,8 @@ class ShellTest(utils.TestCase):
self.useFixture(fixtures.EnvironmentVariable(var,
self.FAKE_ENV[var]))
self.mock_completion()
self.shell = shell.OpenStackCinderShell()
self.requests = self.useFixture(requests_mock_fixture.Fixture())