Debian Codegraph @

keystoneclient/tests/unit/v2_0/test_ec2.py

raw symbols SCIP
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
13 from keystoneclient.tests.unit.v2_0 import utils
14 from keystoneclient.v2_0 import ec2
15
16
17 class EC2Tests(utils.ClientTestCase):
18
19 def test_create(self):
20 user_id = 'usr'
21 tenant_id = 'tnt'
22 req_body = {
23 "tenant_id": tenant_id,
24 }
25 resp_body = {
26 "credential": {
27 "access": "access",
28 "secret": "secret",
29 "tenant_id": tenant_id,
30 "created": "12/12/12",
31 "enabled": True,
32 }
33 }
34 self.stub_url('POST', ['users', user_id, 'credentials',
35 'OS-EC2'], json=resp_body)
36
37 cred = self.client.ec2.create(user_id, tenant_id)
38 self.assertIsInstance(cred, ec2.EC2)
39 self.assertEqual(cred.tenant_id, tenant_id)
40 self.assertEqual(cred.enabled, True)
41 self.assertEqual(cred.access, 'access')
42 self.assertEqual(cred.secret, 'secret')
43 self.assertRequestBodyIs(json=req_body)
44
45 def test_get(self):
46 user_id = 'usr'
47 tenant_id = 'tnt'
48 resp_body = {
49 "credential": {
50 "access": "access",
51 "secret": "secret",
52 "tenant_id": tenant_id,
53 "created": "12/12/12",
54 "enabled": True,
55 }
56 }
57 self.stub_url('GET', ['users', user_id, 'credentials',
58 'OS-EC2', 'access'], json=resp_body)
59
60 cred = self.client.ec2.get(user_id, 'access')
61 self.assertIsInstance(cred, ec2.EC2)
62 self.assertEqual(cred.tenant_id, tenant_id)
63 self.assertEqual(cred.enabled, True)
64 self.assertEqual(cred.access, 'access')
65 self.assertEqual(cred.secret, 'secret')
66
67 def test_list(self):
68 user_id = 'usr'
69 tenant_id = 'tnt'
70 resp_body = {
71 "credentials": {
72 "values": [
73 {
74 "access": "access",
75 "secret": "secret",
76 "tenant_id": tenant_id,
77 "created": "12/12/12",
78 "enabled": True,
79 },
80 {
81 "access": "another",
82 "secret": "key",
83 "tenant_id": tenant_id,
84 "created": "12/12/31",
85 "enabled": True,
86 }
87 ]
88 }
89 }
90 self.stub_url('GET', ['users', user_id, 'credentials',
91 'OS-EC2'], json=resp_body)
92
93 creds = self.client.ec2.list(user_id)
94 self.assertEqual(len(creds), 2)
95 cred = creds[0]
96 self.assertIsInstance(cred, ec2.EC2)
97 self.assertEqual(cred.tenant_id, tenant_id)
98 self.assertEqual(cred.enabled, True)
99 self.assertEqual(cred.access, 'access')
100 self.assertEqual(cred.secret, 'secret')
101
102 def test_delete(self):
103 user_id = 'usr'
104 access = 'access'
105 self.stub_url('DELETE', ['users', user_id, 'credentials',
106 'OS-EC2', access], status_code=204)
107 self.client.ec2.delete(user_id, access)