summaryrefslogtreecommitdiff
path: root/novaclient/tests/unit/v2/test_keypairs.py
diff options
context:
space:
mode:
Diffstat (limited to 'novaclient/tests/unit/v2/test_keypairs.py')
-rw-r--r--novaclient/tests/unit/v2/test_keypairs.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/novaclient/tests/unit/v2/test_keypairs.py b/novaclient/tests/unit/v2/test_keypairs.py
new file mode 100644
index 0000000..91c249f
--- /dev/null
+++ b/novaclient/tests/unit/v2/test_keypairs.py
@@ -0,0 +1,64 @@
1#
2# Licensed under the Apache License, Version 2.0 (the "License"); you may
3# not use this file except in compliance with the License. You may obtain
4# a copy of the License at
5#
6# http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11# License for the specific language governing permissions and limitations
12# under the License.
13
14from novaclient.tests.unit.fixture_data import client
15from novaclient.tests.unit.fixture_data import keypairs as data
16from novaclient.tests.unit import utils
17from novaclient.v2 import keypairs
18
19
20class KeypairsTest(utils.FixturedTestCase):
21
22 client_fixture_class = client.V1
23 data_fixture_class = data.V1
24
25 def setUp(self):
26 super(KeypairsTest, self).setUp()
27 self.keypair_type = self._get_keypair_type()
28 self.keypair_prefix = self._get_keypair_prefix()
29
30 def _get_keypair_type(self):
31 return keypairs.Keypair
32
33 def _get_keypair_prefix(self):
34 return keypairs.KeypairManager.keypair_prefix
35
36 def test_get_keypair(self):
37 kp = self.cs.keypairs.get('test')
38 self.assert_called('GET', '/%s/test' % self.keypair_prefix)
39 self.assertIsInstance(kp, keypairs.Keypair)
40 self.assertEqual('test', kp.name)
41
42 def test_list_keypairs(self):
43 kps = self.cs.keypairs.list()
44 self.assert_called('GET', '/%s' % self.keypair_prefix)
45 [self.assertIsInstance(kp, keypairs.Keypair) for kp in kps]
46
47 def test_delete_keypair(self):
48 kp = self.cs.keypairs.list()[0]
49 kp.delete()
50 self.assert_called('DELETE', '/%s/test' % self.keypair_prefix)
51 self.cs.keypairs.delete('test')
52 self.assert_called('DELETE', '/%s/test' % self.keypair_prefix)
53 self.cs.keypairs.delete(kp)
54 self.assert_called('DELETE', '/%s/test' % self.keypair_prefix)
55
56 def test_create_keypair(self):
57 kp = self.cs.keypairs.create("foo")
58 self.assert_called('POST', '/%s' % self.keypair_prefix)
59 self.assertIsInstance(kp, keypairs.Keypair)
60
61 def test_import_keypair(self):
62 kp = self.cs.keypairs.create("foo", "fake-public-key")
63 self.assert_called('POST', '/%s' % self.keypair_prefix)
64 self.assertIsInstance(kp, keypairs.Keypair)