summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Tantsur <divius.inside@gmail.com>2019-05-20 11:25:12 +0200
committerDmitry Tantsur <divius.inside@gmail.com>2019-05-20 14:26:21 +0000
commit4e2345ec47a32e7710736b2db2081ac557e9f9b7 (patch)
treea08ce5aa9f9859dd085cc702c9d0c8d5f635ddbd
parentb980a85917beaf69eefc334d2e84d780ac75e17a (diff)
downloadironic-4e2345ec47a32e7710736b2db2081ac557e9f9b7.tar.gz
Do not try to return mock as JSON in unit tests
A few of our unit tests make API handlers return Mock objects. This used to work with older WSME, but the current master has dropped support for simplejson, which has apparently made validation stricter. An example of resulting failures can be seen in RDO CI: https://trunk.rdoproject.org/centos7/71/83/71833957b3e9c4bdc7b1992e768e1b01a9339e97_156a4cd0/mock.log This change fixes it, also adding autospec=True to affected tests. Change-Id: Ide4bc301d53ad81b53e5df8a9358cb65fdd8056c (cherry picked from commit f8e1fbf30879e883f2e77386b7f275fd5afbff25)
-rw-r--r--ironic/tests/unit/api/controllers/v1/test_node.py18
-rw-r--r--ironic/tests/unit/api/controllers/v1/test_port.py10
2 files changed, 18 insertions, 10 deletions
diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py
index 43de1d8a2..1e574372e 100644
--- a/ironic/tests/unit/api/controllers/v1/test_node.py
+++ b/ironic/tests/unit/api/controllers/v1/test_node.py
@@ -1370,20 +1370,24 @@ class TestListNodes(test_api_base.BaseApiTest):
self.assertTrue(ret.json['error_message'])
mock_gsbd.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
- @mock.patch.object(rpcapi.ConductorAPI, 'validate_driver_interfaces')
+ @mock.patch.object(rpcapi.ConductorAPI, 'validate_driver_interfaces',
+ autospec=True, return_value={})
def test_validate_by_uuid_using_deprecated_interface(self, mock_vdi):
# Note(mrda): The 'node_uuid' interface is deprecated in favour
# of the 'node' interface
node = obj_utils.create_test_node(self.context)
self.get_json('/nodes/validate?node_uuid=%s' % node.uuid)
- mock_vdi.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
+ mock_vdi.assert_called_once_with(mock.ANY, mock.ANY,
+ node.uuid, 'test-topic')
- @mock.patch.object(rpcapi.ConductorAPI, 'validate_driver_interfaces')
+ @mock.patch.object(rpcapi.ConductorAPI, 'validate_driver_interfaces',
+ autospec=True, return_value={})
def test_validate_by_uuid(self, mock_vdi):
node = obj_utils.create_test_node(self.context)
self.get_json('/nodes/validate?node=%s' % node.uuid,
headers={api_base.Version.string: "1.5"})
- mock_vdi.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
+ mock_vdi.assert_called_once_with(mock.ANY, mock.ANY,
+ node.uuid, 'test-topic')
@mock.patch.object(rpcapi.ConductorAPI, 'validate_driver_interfaces')
def test_validate_by_name_unsupported(self, mock_vdi):
@@ -1393,14 +1397,16 @@ class TestListNodes(test_api_base.BaseApiTest):
self.assertEqual(http_client.NOT_ACCEPTABLE, ret.status_code)
self.assertFalse(mock_vdi.called)
- @mock.patch.object(rpcapi.ConductorAPI, 'validate_driver_interfaces')
+ @mock.patch.object(rpcapi.ConductorAPI, 'validate_driver_interfaces',
+ autospec=True, return_value={})
def test_validate_by_name(self, mock_vdi):
node = obj_utils.create_test_node(self.context, name='spam')
self.get_json('/nodes/validate?node=%s' % node.name,
headers={api_base.Version.string: "1.5"})
# note that this should be node.uuid here as we get that from the
# rpc_node lookup and pass that downwards
- mock_vdi.assert_called_once_with(mock.ANY, node.uuid, 'test-topic')
+ mock_vdi.assert_called_once_with(mock.ANY, mock.ANY,
+ node.uuid, 'test-topic')
def test_ssh_creds_masked(self):
driver_info = {"ssh_password": "password", "ssh_key_contents": "key"}
diff --git a/ironic/tests/unit/api/controllers/v1/test_port.py b/ironic/tests/unit/api/controllers/v1/test_port.py
index 0effedd64..adc3ac263 100644
--- a/ironic/tests/unit/api/controllers/v1/test_port.py
+++ b/ironic/tests/unit/api/controllers/v1/test_port.py
@@ -711,15 +711,17 @@ class TestListPorts(test_api_base.BaseApiTest):
self.assertEqual('application/json', response.content_type)
self.assertEqual(http_client.FORBIDDEN, response.status_int)
- @mock.patch.object(api_port.PortsController, '_get_ports_collection')
+ @mock.patch.object(api_port.PortsController, '_get_ports_collection',
+ autospec=True)
def test_detail_with_incorrect_api_usage(self, mock_gpc):
+ mock_gpc.return_value = api_port.PortCollection.convert_with_links(
+ [], 0)
# GET /v1/ports/detail specifying node and node_uuid. In this case
# we expect the node_uuid interface to be used.
self.get_json('/ports/detail?node=%s&node_uuid=%s' %
('test-node', self.node.uuid))
- mock_gpc.assert_called_once_with(self.node.uuid, mock.ANY, mock.ANY,
- mock.ANY, mock.ANY, mock.ANY,
- mock.ANY, mock.ANY)
+ self.assertEqual(1, mock_gpc.call_count)
+ self.assertEqual(self.node.uuid, mock_gpc.call_args[0][1])
def test_portgroups_subresource_node_not_found(self):
non_existent_uuid = 'eeeeeeee-cccc-aaaa-bbbb-cccccccccccc'