From 6dc17bb1fbb0b265223aff90a585be43830b1ac1 Mon Sep 17 00:00:00 2001 From: David Rabel Date: Fri, 21 Apr 2017 09:23:44 +0000 Subject: [PATCH] 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 --- .../tests/unit/compute/v2/test_server.py | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py index 600b872e54..3ffe642810 100644 --- a/openstackclient/tests/unit/compute/v2/test_server.py +++ b/openstackclient/tests/unit/compute/v2/test_server.py @@ -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,