From 52991a1b4331767bd179765d7c67a1e9110b27b3 Mon Sep 17 00:00:00 2001 From: JinLi Date: Wed, 27 Apr 2016 22:34:02 +0000 Subject: [PATCH] Remove iterated form of side effects to simplify code remove iterated form of side effects from some test cases that are simulating single exception/error Change-Id: I5e9cb760587a48d8bbe059191f3605f6ed547a44 Closes-Bug: #1564392 --- ironic_inspector/test/unit/test_introspect.py | 6 +++--- ironic_inspector/test/unit/test_main.py | 16 ++++++++-------- ironic_inspector/test/unit/test_process.py | 1 - 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/ironic_inspector/test/unit/test_introspect.py b/ironic_inspector/test/unit/test_introspect.py index 3a093fa73..bf752c706 100644 --- a/ironic_inspector/test/unit/test_introspect.py +++ b/ironic_inspector/test/unit/test_introspect.py @@ -444,7 +444,7 @@ class TestAbort(BaseTest): def test_node_not_found(self, client_mock, get_mock, filters_mock): cli = self._prepare(client_mock) exc = utils.Error('Not found.', code=404) - get_mock.side_effect = iter([exc]) + get_mock.side_effect = exc self.assertRaisesRegexp(utils.Error, str(exc), introspect.abort, self.uuid) @@ -487,7 +487,7 @@ class TestAbort(BaseTest): self.node_info.acquire_lock.return_value = True self.node_info.started_at = time.time() self.node_info.finished_at = None - filters_mock.side_effect = iter([Exception('Boom')]) + filters_mock.side_effect = Exception('Boom') introspect.abort(self.uuid) @@ -506,7 +506,7 @@ class TestAbort(BaseTest): self.node_info.acquire_lock.return_value = True self.node_info.started_at = time.time() self.node_info.finished_at = None - cli.node.set_power_state.side_effect = iter([Exception('BadaBoom')]) + cli.node.set_power_state.side_effect = Exception('BadaBoom') introspect.abort(self.uuid) diff --git a/ironic_inspector/test/unit/test_main.py b/ironic_inspector/test/unit/test_main.py index d7b727d87..daa77d7fb 100644 --- a/ironic_inspector/test/unit/test_main.py +++ b/ironic_inspector/test/unit/test_main.py @@ -82,7 +82,7 @@ class TestApiIntrospect(BaseAPITest): @mock.patch.object(introspect, 'introspect', autospec=True) def test_intospect_failed(self, introspect_mock): - introspect_mock.side_effect = iter([utils.Error("boom")]) + introspect_mock.side_effect = utils.Error("boom") res = self.app.post('/v1/introspection/%s' % self.uuid) self.assertEqual(400, res.status_code) self.assertEqual( @@ -98,7 +98,7 @@ class TestApiIntrospect(BaseAPITest): def test_introspect_failed_authentication(self, introspect_mock, auth_mock): CONF.set_override('auth_strategy', 'keystone') - auth_mock.side_effect = iter([utils.Error('Boom', code=403)]) + auth_mock.side_effect = utils.Error('Boom', code=403) res = self.app.post('/v1/introspection/%s' % self.uuid, headers={'X-Auth-Token': 'token'}) self.assertEqual(403, res.status_code) @@ -117,7 +117,7 @@ class TestApiContinue(BaseAPITest): self.assertEqual({"result": 42}, json.loads(res.data.decode())) def test_continue_failed(self, process_mock): - process_mock.side_effect = iter([utils.Error("boom")]) + process_mock.side_effect = utils.Error("boom") res = self.app.post('/v1/continue', data='{"foo": "bar"}') self.assertEqual(400, res.status_code) process_mock.assert_called_once_with({"foo": "bar"}) @@ -154,7 +154,7 @@ class TestApiAbort(BaseAPITest): def test_node_not_found(self, abort_mock): exc = utils.Error("Not Found.", code=404) - abort_mock.side_effect = iter([exc]) + abort_mock.side_effect = exc res = self.app.post('/v1/introspection/%s/abort' % self.uuid) @@ -165,7 +165,7 @@ class TestApiAbort(BaseAPITest): def test_abort_failed(self, abort_mock): exc = utils.Error("Locked.", code=409) - abort_mock.side_effect = iter([exc]) + abort_mock.side_effect = exc res = self.app.post('/v1/introspection/%s/abort' % self.uuid) @@ -411,7 +411,7 @@ class TestApiRules(BaseAPITest): class TestApiMisc(BaseAPITest): @mock.patch.object(node_cache, 'get_node', autospec=True) def test_404_expected(self, get_mock): - get_mock.side_effect = iter([utils.Error('boom', code=404)]) + get_mock.side_effect = utils.Error('boom', code=404) res = self.app.get('/v1/introspection/%s' % self.uuid) self.assertEqual(404, res.status_code) self.assertEqual('boom', _get_error(res)) @@ -424,7 +424,7 @@ class TestApiMisc(BaseAPITest): @mock.patch.object(node_cache, 'get_node', autospec=True) def test_500_with_debug(self, get_mock): CONF.set_override('debug', True) - get_mock.side_effect = iter([RuntimeError('boom')]) + get_mock.side_effect = RuntimeError('boom') res = self.app.get('/v1/introspection/%s' % self.uuid) self.assertEqual(500, res.status_code) self.assertEqual('Internal server error (RuntimeError): boom', @@ -433,7 +433,7 @@ class TestApiMisc(BaseAPITest): @mock.patch.object(node_cache, 'get_node', autospec=True) def test_500_without_debug(self, get_mock): CONF.set_override('debug', False) - get_mock.side_effect = iter([RuntimeError('boom')]) + get_mock.side_effect = RuntimeError('boom') res = self.app.get('/v1/introspection/%s' % self.uuid) self.assertEqual(500, res.status_code) self.assertEqual('Internal server error', diff --git a/ironic_inspector/test/unit/test_process.py b/ironic_inspector/test/unit/test_process.py index 0e948aeb7..c9ff752c3 100644 --- a/ironic_inspector/test/unit/test_process.py +++ b/ironic_inspector/test/unit/test_process.py @@ -119,7 +119,6 @@ class TestProcess(BaseProcessTest): def test_not_found_in_cache(self): self.find_mock.side_effect = utils.Error('not found') - self.assertRaisesRegexp(utils.Error, 'not found', process.process, self.data)