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:71833957b3
_156a4cd0/mock.log This change fixes it, also adding autospec=True to affected tests. Change-Id: Ide4bc301d53ad81b53e5df8a9358cb65fdd8056c (cherry picked from commitf8e1fbf308
)
This commit is contained in:
parent
b980a85917
commit
4e2345ec47
|
@ -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"}
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in New Issue