summaryrefslogtreecommitdiff
path: root/openstackclient/tests/compute/v2/fakes.py
diff options
context:
space:
mode:
authorjichenjc <jichenjc@cn.ibm.com>2016-02-21 08:30:54 +0800
committerjichenjc <jichenjc@cn.ibm.com>2016-02-23 12:23:10 +0800
commit042e2b7d53222618c76870effa3d74759ccc696a (patch)
tree92d2b7aa579244c67b1fe128061ea9304e08faf5 /openstackclient/tests/compute/v2/fakes.py
parentb5b5fdd78ad0d191bdf07a56293fecaa43002e75 (diff)
downloadpython-openstackclient-042e2b7d53222618c76870effa3d74759ccc696a.tar.gz
[compute] Add unit test for keypair
keypair do not have unit test, this patch adds it. Change-Id: Id702ccaad239b916340bb17014d1ede0a28aaec9
Diffstat (limited to 'openstackclient/tests/compute/v2/fakes.py')
-rw-r--r--openstackclient/tests/compute/v2/fakes.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py
index f4d79ff7..a9c7154a 100644
--- a/openstackclient/tests/compute/v2/fakes.py
+++ b/openstackclient/tests/compute/v2/fakes.py
@@ -137,6 +137,9 @@ class FakeComputev2Client(object):
self.networks = mock.Mock()
self.networks.resource_class = fakes.FakeResource(None, {})
+ self.keypairs = mock.Mock()
+ self.keypairs.resource_class = fakes.FakeResource(None, {})
+
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
@@ -534,6 +537,58 @@ class FakeFlavor(object):
return mock.MagicMock(side_effect=flavors)
+class FakeKeypair(object):
+ """Fake one or more keypairs."""
+
+ @staticmethod
+ def create_one_keypair(attrs=None, no_pri=False):
+ """Create a fake keypair
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource
+ """
+ # Set default attributes.
+ if attrs is None:
+ attrs = {}
+
+ keypair_info = {
+ 'name': 'keypair-name-' + uuid.uuid4().hex,
+ 'fingerprint': 'dummy',
+ 'public_key': 'dummy',
+ 'user_id': 'user'
+ }
+ if not no_pri:
+ keypair_info['private_key'] = 'private_key'
+
+ # Overwrite default attributes.
+ keypair_info.update(attrs)
+
+ keypair = fakes.FakeResource(info=copy.deepcopy(keypair_info),
+ loaded=True)
+
+ return keypair
+
+ @staticmethod
+ def create_keypairs(attrs=None, count=2):
+ """Create multiple fake flavors.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :param int count:
+ The number of flavors to fake
+ :return:
+ A list of FakeFlavorResource objects faking the flavors
+ """
+
+ keypairs = []
+ for i in range(0, count):
+ keypairs.append(FakeKeypair.create_one_keypair(attrs))
+
+ return keypairs
+
+
class FakeAvailabilityZone(object):
"""Fake one or more compute availability zones (AZs)."""