From a39805c6f45baf94c0d14da3ae775ee204a267ee Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Tue, 26 Feb 2019 14:13:52 -0500 Subject: [PATCH] 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 --- cinderclient/base.py | 2 ++ cinderclient/tests/unit/test_shell.py | 11 +++++++++++ cinderclient/tests/unit/utils.py | 14 ++++++++++++++ cinderclient/tests/unit/v1/test_shell.py | 2 ++ cinderclient/tests/unit/v2/test_shell.py | 2 ++ cinderclient/tests/unit/v3/test_shell.py | 2 ++ 6 files changed, 33 insertions(+) diff --git a/cinderclient/base.py b/cinderclient/base.py index 77630a661..99c847dc8 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 a5ed614b5..4702671ec 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())