summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorTang Chen <chen.tang@easystack.cn>2016-02-16 15:11:19 +0800
committerTang Chen <chen.tang@easystack.cn>2016-02-16 15:14:34 +0800
commitda3d65299bc168ca86bfb4055d08556715149e0f (patch)
tree141f816cd1e4a60ead5cc0c0ee1603a65cc18d19 /openstackclient/tests
parentc8753808a224a6f286d1ee7833fb905ac916f304 (diff)
downloadpython-openstackclient-da3d65299bc168ca86bfb4055d08556715149e0f.tar.gz
Define FakeFloatingIP class in tests/compute for nova network commands
"ip floating list" command is not available for Neutron now because the implementation is incorrect. The FloatingIP objects returned from Nova and Neutron network are quite different. So they need different FakeFloatingIP class to do the tests. This patch copies class FakeFloatingIP in tests/network to tests/compute for Nova network tests. Will fix the problem in "ip floating list" command and change FakeFloatingIP in tests/network to fit Neutron network tests. Change-Id: Ia29d257868e0f1dc6cd7cfe3819875e5913f76ec Partial-Bug: 1519502 Partially implements: blueprint neutron-client
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/compute/v2/fakes.py79
-rw-r--r--openstackclient/tests/network/v2/test_floating_ip.py4
2 files changed, 81 insertions, 2 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py
index c5e8f412..00f73748 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -446,3 +446,82 @@ class FakeAvailabilityZone(object):
availability_zones.append(availability_zone)
return availability_zones
+
+
+class FakeFloatingIP(object):
+ """Fake one or more floating ip."""
+
+ @staticmethod
+ def create_one_floating_ip(attrs={}, methods={}):
+ """Create a fake floating ip.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :return:
+ A FakeResource object, with id, ip, and so on
+ """
+ # Set default attributes.
+ floating_ip_attrs = {
+ 'id': 'floating-ip-id-' + uuid.uuid4().hex,
+ 'ip': '1.0.9.0',
+ 'fixed_ip': '2.0.9.0',
+ 'instance_id': 'server-id-' + uuid.uuid4().hex,
+ 'pool': 'public',
+ }
+
+ # Overwrite default attributes.
+ floating_ip_attrs.update(attrs)
+
+ # Set default methods.
+ floating_ip_methods = {}
+
+ # Overwrite default methods.
+ floating_ip_methods.update(methods)
+
+ floating_ip = fakes.FakeResource(
+ info=copy.deepcopy(floating_ip_attrs),
+ methods=copy.deepcopy(floating_ip_methods),
+ loaded=True)
+ return floating_ip
+
+ @staticmethod
+ def create_floating_ips(attrs={}, methods={}, count=2):
+ """Create multiple fake floating ips.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param Dictionary methods:
+ A dictionary with all methods
+ :param int count:
+ The number of floating ips to fake
+ :return:
+ A list of FakeResource objects faking the floating ips
+ """
+ floating_ips = []
+ for i in range(0, count):
+ floating_ips.append(FakeFloatingIP.create_one_floating_ip(
+ attrs,
+ methods
+ ))
+ return floating_ips
+
+ @staticmethod
+ def get_floating_ips(floating_ips=None, count=2):
+ """Get an iterable MagicMock object with a list of faked floating ips.
+
+ If floating_ips list is provided, then initialize the Mock object
+ with the list. Otherwise create one.
+
+ :param List floating ips:
+ A list of FakeResource objects faking floating ips
+ :param int count:
+ The number of floating ips to fake
+ :return:
+ An iterable Mock object with side_effect set to a list of faked
+ floating ips
+ """
+ if floating_ips is None:
+ floating_ips = FakeFloatingIP.create_floating_ips(count)
+ return mock.MagicMock(side_effect=floating_ips)
diff --git a/openstackclient/tests/network/v2/test_floating_ip.py b/openstackclient/tests/network/v2/test_floating_ip.py
index cfe3d11d..031dcdac 100644
--- a/openstackclient/tests/network/v2/test_floating_ip.py
+++ b/openstackclient/tests/network/v2/test_floating_ip.py
@@ -110,7 +110,7 @@ class TestFloatingIPCompute(compute_fakes.TestComputev2):
class TestDeleteFloatingIPCompute(TestFloatingIPCompute):
# The floating ip to be deleted.
- floating_ip = network_fakes.FakeFloatingIP.create_one_floating_ip()
+ floating_ip = compute_fakes.FakeFloatingIP.create_one_floating_ip()
def setUp(self):
super(TestDeleteFloatingIPCompute, self).setUp()
@@ -145,7 +145,7 @@ class TestDeleteFloatingIPCompute(TestFloatingIPCompute):
class TestListFloatingIPCompute(TestFloatingIPCompute):
# The floating ips to be list up
- floating_ips = network_fakes.FakeFloatingIP.create_floating_ips(count=3)
+ floating_ips = compute_fakes.FakeFloatingIP.create_floating_ips(count=3)
columns = ('ID', 'Floating IP', 'Fixed IP', 'Server ID', 'Pool')