Merge "Enforce autospec in test_volume_target"
This commit is contained in:
commit
23157bc1dc
@ -319,7 +319,7 @@ class TestListVolumeTargets(test_api_base.BaseApiTest):
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertIn(invalid_key, response.json['error_message'])
|
||||
|
||||
@mock.patch.object(api_utils, 'get_rpc_node')
|
||||
@mock.patch.object(api_utils, 'get_rpc_node', autospec=True)
|
||||
def test_get_all_by_node_name_ok(self, mock_get_rpc_node):
|
||||
# GET /v1/volume/targets specifying node_name - success
|
||||
mock_get_rpc_node.return_value = self.node
|
||||
@ -335,7 +335,7 @@ class TestListVolumeTargets(test_api_base.BaseApiTest):
|
||||
headers=self.headers)
|
||||
self.assertEqual(3, len(data['targets']))
|
||||
|
||||
@mock.patch.object(api_utils, 'get_rpc_node')
|
||||
@mock.patch.object(api_utils, 'get_rpc_node', autospec=True)
|
||||
def test_detail_by_node_name_ok(self, mock_get_rpc_node):
|
||||
# GET /v1/volume/targets/?detail=True specifying node_name - success
|
||||
mock_get_rpc_node.return_value = self.node
|
||||
@ -348,7 +348,7 @@ class TestListVolumeTargets(test_api_base.BaseApiTest):
|
||||
self.assertEqual(self.node.uuid, data['targets'][0]['node_uuid'])
|
||||
|
||||
|
||||
@mock.patch.object(rpcapi.ConductorAPI, 'update_volume_target')
|
||||
@mock.patch.object(rpcapi.ConductorAPI, 'update_volume_target', autospec=True)
|
||||
class TestPatch(test_api_base.BaseApiTest):
|
||||
headers = {api_base.Version.string: str(api_v1.max_version())}
|
||||
|
||||
@ -358,12 +358,14 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.target = obj_utils.create_test_volume_target(
|
||||
self.context, node_id=self.node.id)
|
||||
|
||||
p = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for')
|
||||
p = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for',
|
||||
autospec=True)
|
||||
self.mock_gtf = p.start()
|
||||
self.mock_gtf.return_value = 'test-topic'
|
||||
self.addCleanup(p.stop)
|
||||
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification')
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification',
|
||||
autospec=True)
|
||||
def test_update_byid(self, mock_notify, mock_upd):
|
||||
extra = {'foo': 'bar'}
|
||||
mock_upd.return_value = self.target
|
||||
@ -378,7 +380,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertEqual(http_client.OK, response.status_code)
|
||||
self.assertEqual(extra, response.json['extra'])
|
||||
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(extra, kargs.extra)
|
||||
mock_notify.assert_has_calls([mock.call(mock.ANY, mock.ANY, 'update',
|
||||
obj_fields.NotificationLevel.INFO,
|
||||
@ -427,10 +429,11 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertEqual(boot_index, response.json['boot_index'])
|
||||
self.assertTrue(mock_upd.called)
|
||||
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(boot_index, kargs.boot_index)
|
||||
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification')
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification',
|
||||
autospec=True)
|
||||
def test_replace_boot_index_already_exist(self, mock_notify, mock_upd):
|
||||
boot_index = 100
|
||||
mock_upd.side_effect = \
|
||||
@ -446,7 +449,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertTrue(response.json['error_message'])
|
||||
self.assertTrue(mock_upd.called)
|
||||
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(boot_index, kargs.boot_index)
|
||||
mock_notify.assert_has_calls([mock.call(mock.ANY, mock.ANY, 'update',
|
||||
obj_fields.NotificationLevel.INFO,
|
||||
@ -473,7 +476,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertTrue(response.json['error_message'])
|
||||
self.assertTrue(mock_upd.called)
|
||||
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(0, kargs.boot_index)
|
||||
|
||||
def test_replace_node_uuid(self, mock_upd):
|
||||
@ -595,7 +598,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertEqual(http_client.OK, response.status_code)
|
||||
self.assertEqual(extra, response.json['extra'])
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(extra, kargs.extra)
|
||||
|
||||
def test_remove_multi(self, mock_upd):
|
||||
@ -615,7 +618,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertEqual(http_client.OK, response.status_code)
|
||||
self.assertEqual(extra, response.json['extra'])
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(extra, kargs.extra)
|
||||
|
||||
# Remove the collection.
|
||||
@ -628,7 +631,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertEqual(http_client.OK, response.status_code)
|
||||
self.assertEqual({}, response.json['extra'])
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(extra, kargs.extra)
|
||||
|
||||
# Assert nothing else was changed.
|
||||
@ -675,7 +678,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertEqual(http_client.OK, response.status_code)
|
||||
self.assertEqual(boot_index, response.json['boot_index'])
|
||||
self.assertTrue(mock_upd.called)
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(boot_index, kargs.boot_index)
|
||||
|
||||
def test_add_root_non_existent(self, mock_upd):
|
||||
@ -707,7 +710,7 @@ class TestPatch(test_api_base.BaseApiTest):
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertEqual(http_client.OK, response.status_code)
|
||||
self.assertEqual(extra, response.json['extra'])
|
||||
kargs = mock_upd.call_args[0][1]
|
||||
kargs = mock_upd.call_args[0][2]
|
||||
self.assertEqual(extra, kargs.extra)
|
||||
|
||||
def test_remove_uuid(self, mock_upd):
|
||||
@ -730,8 +733,9 @@ class TestPost(test_api_base.BaseApiTest):
|
||||
super(TestPost, self).setUp()
|
||||
self.node = obj_utils.create_test_node(self.context)
|
||||
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification')
|
||||
@mock.patch.object(timeutils, 'utcnow')
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification',
|
||||
autospec=True)
|
||||
@mock.patch.object(timeutils, 'utcnow', autospec=True)
|
||||
def test_create_volume_target(self, mock_utcnow, mock_notify):
|
||||
pdict = post_get_test_volume_target()
|
||||
test_time = datetime.datetime(2000, 1, 1, 0, 0)
|
||||
@ -797,8 +801,9 @@ class TestPost(test_api_base.BaseApiTest):
|
||||
self.assertFalse(mock_warning.called)
|
||||
self.assertFalse(mock_exception.called)
|
||||
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification')
|
||||
@mock.patch.object(objects.VolumeTarget, 'create')
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification',
|
||||
autospec=True)
|
||||
@mock.patch.object(objects.VolumeTarget, 'create', autospec=True)
|
||||
def test_create_volume_target_error(self, mock_create, mock_notify):
|
||||
mock_create.side_effect = Exception()
|
||||
tdict = post_get_test_volume_target()
|
||||
@ -880,7 +885,8 @@ class TestPost(test_api_base.BaseApiTest):
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
|
||||
@mock.patch.object(rpcapi.ConductorAPI, 'destroy_volume_target')
|
||||
@mock.patch.object(rpcapi.ConductorAPI, 'destroy_volume_target',
|
||||
autospec=True)
|
||||
class TestDelete(test_api_base.BaseApiTest):
|
||||
headers = {api_base.Version.string: str(api_v1.max_version())}
|
||||
|
||||
@ -890,12 +896,14 @@ class TestDelete(test_api_base.BaseApiTest):
|
||||
self.target = obj_utils.create_test_volume_target(
|
||||
self.context, node_id=self.node.id)
|
||||
|
||||
gtf = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for')
|
||||
gtf = mock.patch.object(rpcapi.ConductorAPI, 'get_topic_for',
|
||||
autospec=True)
|
||||
self.mock_gtf = gtf.start()
|
||||
self.mock_gtf.return_value = 'test-topic'
|
||||
self.addCleanup(gtf.stop)
|
||||
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification')
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification',
|
||||
autospec=True)
|
||||
def test_delete_volume_target_byid(self, mock_notify, mock_dvc):
|
||||
self.delete('/volume/targets/%s' % self.target.uuid,
|
||||
headers=self.headers,
|
||||
@ -917,7 +925,8 @@ class TestDelete(test_api_base.BaseApiTest):
|
||||
expect_errors=True)
|
||||
self.assertEqual(http_client.NOT_FOUND, response.status_int)
|
||||
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification')
|
||||
@mock.patch.object(notification_utils, '_emit_api_notification',
|
||||
autospec=True)
|
||||
def test_delete_volume_target_node_locked(self, mock_notify, mock_dvc):
|
||||
self.node.reserve(self.context, 'fake', self.node.uuid)
|
||||
mock_dvc.side_effect = exception.NodeLocked(node='fake-node',
|
||||
|
1
tox.ini
1
tox.ini
@ -140,7 +140,6 @@ enable-extensions=H106,H203,H204,H205,H210,H904
|
||||
per-file-ignores =
|
||||
ironic/cmd/__init__.py:E402
|
||||
ironic/tests/base.py:E402
|
||||
ironic/tests/unit/api/controllers/v1/test_volume_target.py:H210
|
||||
ironic/tests/unit/api/controllers/v1/test_volume_connector.py:H210
|
||||
ironic/tests/unit/api/controllers/v1/test_portgroup.py:H210
|
||||
ironic/tests/unit/api/controllers/v1/test_port.py:H210
|
||||
|
Loading…
x
Reference in New Issue
Block a user