1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5#      http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13from openstack.compute.v2 import keypair
14from openstack.tests.unit import base
15
16
17EXAMPLE = {
18    'created_at': 'some_time',
19    'deleted': False,
20    'fingerprint': '1',
21    'name': '2',
22    'public_key': '3',
23    'private_key': '4',
24    'type': 'ssh',
25    'user_id': '5'
26}
27
28
29class TestKeypair(base.TestCase):
30
31    def test_basic(self):
32        sot = keypair.Keypair()
33        self.assertEqual('keypair', sot.resource_key)
34        self.assertEqual('keypairs', sot.resources_key)
35        self.assertEqual('/os-keypairs', sot.base_path)
36        self.assertTrue(sot.allow_create)
37        self.assertTrue(sot.allow_fetch)
38        self.assertFalse(sot.allow_commit)
39        self.assertTrue(sot.allow_delete)
40        self.assertTrue(sot.allow_list)
41
42        self.assertDictEqual({'limit': 'limit',
43                              'marker': 'marker',
44                              'user_id': 'user_id'},
45                             sot._query_mapping._mapping)
46
47    def test_make_it(self):
48        sot = keypair.Keypair(**EXAMPLE)
49        self.assertEqual(EXAMPLE['created_at'], sot.created_at)
50        self.assertEqual(EXAMPLE['deleted'], sot.is_deleted)
51        self.assertEqual(EXAMPLE['fingerprint'], sot.fingerprint)
52        self.assertEqual(EXAMPLE['name'], sot.name)
53        self.assertEqual(EXAMPLE['public_key'], sot.public_key)
54        self.assertEqual(EXAMPLE['private_key'], sot.private_key)
55        self.assertEqual(EXAMPLE['type'], sot.type)
56        self.assertEqual(EXAMPLE['user_id'], sot.user_id)
57
58    def test_make_it_defaults(self):
59        EXAMPLE_DEFAULT = EXAMPLE.copy()
60        EXAMPLE_DEFAULT.pop('type')
61        sot = keypair.Keypair(**EXAMPLE_DEFAULT)
62        self.assertEqual(EXAMPLE['type'], sot.type)
63