Debian Codegraph @

keystoneclient/tests/functional/v3/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 keystoneauth1.exceptions import http
14
15 from keystoneclient.tests.functional import base
16 from keystoneclient.tests.functional.v3 import client_fixtures as fixtures
17
18
19 class EC2TestCase(base.V3ClientTestCase):
20
21 def check_ec2(self, ec2, ec2_ref=None):
22 self.assertIn('self', ec2.links)
23 self.assertIn('/users/%s/credentials/OS-EC2/%s'
24 % (ec2.user_id, ec2.access), ec2.links['self'])
25
26 if ec2_ref:
27 self.assertEqual(ec2_ref['user_id'], ec2.user_id)
28 self.assertEqual(ec2_ref['project_id'], ec2.tenant_id)
29
30 else:
31 self.assertIsNotNone(ec2.user_id)
32 self.assertIsNotNone(ec2.tenant_id)
33
34 def test_create_ec2(self):
35 user = fixtures.User(self.client, self.project_domain_id)
36 self.useFixture(user)
37 project = fixtures.Project(self.client, self.project_domain_id)
38 self.useFixture(project)
39
40 ec2_ref = {'user_id': user.id,
41 'project_id': project.id}
42 ec2 = self.client.ec2.create(**ec2_ref)
43
44 self.addCleanup(self.client.ec2.delete, user.id, ec2.access)
45 self.check_ec2(ec2, ec2_ref)
46
47 def test_get_ec2(self):
48 user = fixtures.User(self.client, self.project_domain_id)
49 self.useFixture(user)
50 project = fixtures.Project(self.client, self.project_domain_id)
51 self.useFixture(project)
52
53 ec2 = fixtures.EC2(self.client, user_id=user.id, project_id=project.id)
54 self.useFixture(ec2)
55
56 ec2_ret = self.client.ec2.get(user.id, ec2.access)
57 self.check_ec2(ec2_ret, ec2.ref)
58
59 def test_list_ec2(self):
60 user_one = fixtures.User(self.client, self.project_domain_id)
61 self.useFixture(user_one)
62 ec2_one = fixtures.EC2(self.client, user_id=user_one.id,
63 project_id=self.project_domain_id)
64 self.useFixture(ec2_one)
65
66 user_two = fixtures.User(self.client, self.project_domain_id)
67 self.useFixture(user_two)
68 ec2_two = fixtures.EC2(self.client, user_id=user_two.id,
69 project_id=self.project_domain_id)
70 self.useFixture(ec2_two)
71
72 ec2_list = self.client.ec2.list(user_one.id)
73
74 # All ec2 are valid
75 for ec2 in ec2_list:
76 self.check_ec2(ec2)
77
78 self.assertIn(ec2_one.entity, ec2_list)
79 self.assertNotIn(ec2_two.entity, ec2_list)
80
81 def test_delete_ec2(self):
82 user = fixtures.User(self.client, self.project_domain_id)
83 self.useFixture(user)
84 project = fixtures.Project(self.client, self.project_domain_id)
85 self.useFixture(project)
86
87 ec2 = self.client.ec2.create(user.id, project.id)
88
89 self.client.ec2.delete(user.id, ec2.access)
90 self.assertRaises(http.NotFound,
91 self.client.ec2.get,
92 user.id, ec2.access)