Make test_server.py more elegant and simple

Use only one line for mocking network resources like ports
and networks in test_server.py.

Change-Id: I451a504c3afdd365e64d66079516ec6308c206db
Depends-On: I624b1bc557a195bdf8a7c5a32dc0e72a6fa8b075
This commit is contained in:
David Rabel 2017-04-21 09:23:44 +00:00
parent 8549071363
commit 6dc17bb1fb

View File

@ -413,24 +413,18 @@ class TestServerCreate(TestServer):
network_client = self.app.client_manager.network
network_client.find_network = find_network
network_client.find_port = find_port
network_resource = mock.Mock()
network_resource.id = 'net1_uuid'
port1_resource = mock.Mock()
port1_resource.id = 'port1_uuid'
port2_resource = mock.Mock()
port2_resource.id = 'port2_uuid'
network_resource = mock.Mock(id='net1_uuid')
port1_resource = mock.Mock(id='port1_uuid')
port2_resource = mock.Mock(id='port2_uuid')
find_network.return_value = network_resource
find_port.side_effect = (lambda port_id, ignore_missing:
{"port1": port1_resource,
"port2": port2_resource}[port_id])
# Mock sdk APIs.
_network = mock.Mock()
_network.id = 'net1_uuid'
_port1 = mock.Mock()
_port1.id = 'port1_uuid'
_port2 = mock.Mock()
_port2.id = 'port2_uuid'
_network = mock.Mock(id='net1_uuid')
_port1 = mock.Mock(id='port1_uuid')
_port2 = mock.Mock(id='port2_uuid')
find_network = mock.Mock()
find_port = mock.Mock()
find_network.return_value = _network
@ -609,8 +603,7 @@ class TestServerCreate(TestServer):
find_port = mock.Mock()
network_client = self.app.client_manager.network
network_client.find_port = find_port
port_resource = mock.Mock()
port_resource.id = 'port1_uuid'
port_resource = mock.Mock(id='port1_uuid')
find_port.return_value = port_resource
self.assertRaises(exceptions.CommandError,