From 4be716eb27752d715ea1140b76e4a03907edd87f Mon Sep 17 00:00:00 2001 From: Tang Chen Date: Fri, 4 Dec 2015 16:30:10 +0800 Subject: Migrate network client to SDK. The previous patches have migrate all network commands to the new version using sdk. This patch will remove the temporary method, and implement a new make_client() to create sdk network client. And also, find() in openstackclient/network/common.py must support sdk. The logic of this function will become much easier than before, so this patch also removes two useless test cases of find(). This patch will also remove the patched methods in tests. Change-Id: Ic2f7bca073beb9757172d16f95d9b82c48cbbc12 Implements: blueprint neutron-client Co-Authored-By: Terry Howe Co-Authored-By: Tang Chen --- openstackclient/tests/network/test_common.py | 33 ++++++++-------------------- 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'openstackclient/tests/network/test_common.py') diff --git a/openstackclient/tests/network/test_common.py b/openstackclient/tests/network/test_common.py index b30fdfcb..58586ac0 100644 --- a/openstackclient/tests/network/test_common.py +++ b/openstackclient/tests/network/test_common.py @@ -13,7 +13,6 @@ import mock -from openstackclient.common import exceptions from openstackclient.network import common from openstackclient.tests import utils @@ -28,45 +27,31 @@ class TestFind(utils.TestCase): super(TestFind, self).setUp() self.mock_client = mock.Mock() self.list_resources = mock.Mock() - self.mock_client.list_resources = self.list_resources - self.matrix = {'id': ID} + self.mock_client.find_resource = self.list_resources + self.resource = mock.Mock() + self.resource.id = ID def test_name(self): - self.list_resources.return_value = {RESOURCES: [self.matrix]} + self.list_resources.return_value = self.resource result = common.find(self.mock_client, RESOURCE, RESOURCES, NAME) self.assertEqual(ID, result) - self.list_resources.assert_called_with(fields='id', name=NAME) + self.list_resources.assert_called_with(NAME, ignore_missing=False) def test_id(self): - self.list_resources.side_effect = [{RESOURCES: []}, - {RESOURCES: [self.matrix]}] + self.list_resources.return_value = self.resource result = common.find(self.mock_client, RESOURCE, RESOURCES, NAME) self.assertEqual(ID, result) - self.list_resources.assert_called_with(fields='id', id=NAME) + self.list_resources.assert_called_with(NAME, ignore_missing=False) def test_nameo(self): - self.list_resources.return_value = {RESOURCES: [self.matrix]} + self.list_resources.return_value = self.resource result = common.find(self.mock_client, RESOURCE, RESOURCES, NAME, name_attr='nameo') self.assertEqual(ID, result) - self.list_resources.assert_called_with(fields='id', nameo=NAME) - - def test_dups(self): - dup = {'id': 'Larry'} - self.list_resources.return_value = {RESOURCES: [self.matrix, dup]} - - self.assertRaises(exceptions.CommandError, common.find, - self.mock_client, RESOURCE, RESOURCES, NAME) - - def test_nada(self): - self.list_resources.side_effect = [{RESOURCES: []}, - {RESOURCES: []}] - - self.assertRaises(exceptions.CommandError, common.find, - self.mock_client, RESOURCE, RESOURCES, NAME) + self.list_resources.assert_called_with(NAME, ignore_missing=False) -- cgit v1.2.1