diff --git a/cinderclient/base.py b/cinderclient/base.py index b263aec1a..da8357376 100644 --- a/cinderclient/base.py +++ b/cinderclient/base.py @@ -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) diff --git a/cinderclient/tests/unit/test_shell.py b/cinderclient/tests/unit/test_shell.py index e611ace7a..b94b8b9bf 100644 --- a/cinderclient/tests/unit/test_shell.py +++ b/cinderclient/tests/unit/test_shell.py @@ -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() diff --git a/cinderclient/tests/unit/utils.py b/cinderclient/tests/unit/utils.py index a19f71047..124b71498 100644 --- a/cinderclient/tests/unit/utils.py +++ b/cinderclient/tests/unit/utils.py @@ -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): diff --git a/cinderclient/tests/unit/v1/test_shell.py b/cinderclient/tests/unit/v1/test_shell.py index 698542cc5..ef5948d5f 100644 --- a/cinderclient/tests/unit/v1/test_shell.py +++ b/cinderclient/tests/unit/v1/test_shell.py @@ -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 diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py index 4e966dd9c..50aad0ea8 100644 --- a/cinderclient/tests/unit/v2/test_shell.py +++ b/cinderclient/tests/unit/v2/test_shell.py @@ -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()) diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index eaba63f9c..b145d8e5e 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -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())