diff options
| author | Jenkins <jenkins@review.openstack.org> | 2016-03-04 23:39:16 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2016-03-04 23:39:16 +0000 |
| commit | 5c1633f5050a21ad1866eb3056df74595780e5ae (patch) | |
| tree | 927fba84bb98294d1586f9673e64b0e392ad97b4 /openstackclient/tests/compute/v2/fakes.py | |
| parent | 3ede46d4d089a315bc1792bca318d8481013b585 (diff) | |
| parent | 042e2b7d53222618c76870effa3d74759ccc696a (diff) | |
| download | python-openstackclient-5c1633f5050a21ad1866eb3056df74595780e5ae.tar.gz | |
Merge "[compute] Add unit test for keypair"
Diffstat (limited to 'openstackclient/tests/compute/v2/fakes.py')
| -rw-r--r-- | openstackclient/tests/compute/v2/fakes.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/openstackclient/tests/compute/v2/fakes.py b/openstackclient/tests/compute/v2/fakes.py index 29baa8e1..32d257f1 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'] @@ -598,6 +601,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).""" |
