Merge "Replace mox with mock"

This commit is contained in:
Zuul 2018-08-08 00:00:01 +00:00 committed by Gerrit Code Review
commit bfa25c5e5c
1 changed files with 25 additions and 16 deletions

View File

@ -52,12 +52,19 @@ class TestGlanceApiCmd(test_utils.BaseTestCase):
store.register_opts(CONF)
self.stubs.Set(glance.common.config, 'load_paste_app',
self._do_nothing)
self.stubs.Set(glance.common.wsgi.Server, 'start',
self._do_nothing)
self.stubs.Set(glance.common.wsgi.Server, 'wait',
self._do_nothing)
self.config_patcher = mock.patch(
'glance.common.config.load_paste_app',
side_effect=self._do_nothing)
self.start_patcher = mock.patch('glance.common.wsgi.Server.start',
side_effect=self._do_nothing)
self.wait_patcher = mock.patch('glance.common.wsgi.Server.wait',
side_effect=self._do_nothing)
self.addCleanup(mock.patch.stopall)
self.config_patcher.start()
self.start_patcher.start()
self.wait_patcher.start()
def tearDown(self):
sys.stderr = sys.__stderr__
@ -70,10 +77,10 @@ class TestGlanceApiCmd(test_utils.BaseTestCase):
def test_worker_creation_failure(self):
failure = exc.WorkerCreationFailure(reason='test')
self.stubs.Set(glance.common.wsgi.Server, 'start',
self._raise(failure))
exit = self.assertRaises(SystemExit, glance.cmd.api.main)
self.assertEqual(2, exit.code)
with mock.patch('glance.common.wsgi.Server.start',
side_effect=self._raise(failure)):
exit = self.assertRaises(SystemExit, glance.cmd.api.main)
self.assertEqual(2, exit.code)
@mock.patch.object(glance.common.config, 'parse_cache_args')
@mock.patch.object(logging, 'setup')
@ -96,11 +103,12 @@ class TestGlanceApiCmd(test_utils.BaseTestCase):
mock.call.mock_cache_clean()]
self.assertEqual(expected_call_sequence, manager.mock_calls)
@mock.patch.object(glance.image_cache.cleaner.Cleaner, 'run')
@mock.patch.object(glance.image_cache.base.CacheApp, '__init__')
def test_cache_cleaner_main_runtime_exception_handling(self, mock_cache):
def test_cache_cleaner_main_runtime_exception_handling(self, mock_cache,
mock_run):
mock_cache.return_value = None
self.stubs.Set(glance.image_cache.cleaner.Cleaner, 'run',
self._raise(RuntimeError))
mock_run.side_effect = self._raise(RuntimeError)
exit = self.assertRaises(SystemExit, glance.cmd.cache_cleaner.main)
self.assertEqual('ERROR: ', exit.code)
@ -125,11 +133,12 @@ class TestGlanceApiCmd(test_utils.BaseTestCase):
mock.call.mock_cache_prune()]
self.assertEqual(expected_call_sequence, manager.mock_calls)
@mock.patch.object(glance.image_cache.pruner.Pruner, 'run')
@mock.patch.object(glance.image_cache.base.CacheApp, '__init__')
def test_cache_pruner_main_runtime_exception_handling(self, mock_cache):
def test_cache_pruner_main_runtime_exception_handling(self, mock_cache,
mock_run):
mock_cache.return_value = None
self.stubs.Set(glance.image_cache.pruner.Pruner, 'run',
self._raise(RuntimeError))
mock_run.side_effect = self._raise(RuntimeError)
exit = self.assertRaises(SystemExit, glance.cmd.cache_pruner.main)
self.assertEqual('ERROR: ', exit.code)