summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient')
-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')