Debian Codegraph @

keystoneclient/tests/functional/v3/test_groups.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 import uuid
14
15 from keystoneauth1.exceptions import http
16 from keystoneclient.tests.functional import base
17 from keystoneclient.tests.functional.v3 import client_fixtures as fixtures
18
19
20 class GroupsTestCase(base.V3ClientTestCase):
21
22 def check_group(self, group, group_ref=None):
23 self.assertIsNotNone(group.id)
24 self.assertIn('self', group.links)
25 self.assertIn('/groups/' + group.id, group.links['self'])
26
27 if group_ref:
28 self.assertEqual(group_ref['name'], group.name)
29 self.assertEqual(group_ref['domain'], group.domain_id)
30
31 # There is no guarantee description is present in group
32 if hasattr(group_ref, 'description'):
33 self.assertEqual(group_ref['description'], group.description)
34
35 else:
36 # Only check remaining mandatory attributes
37 self.assertIsNotNone(group.name)
38 self.assertIsNotNone(group.domain_id)
39
40 def test_create_group(self):
41 group_ref = {
42 'name': fixtures.RESOURCE_NAME_PREFIX + uuid.uuid4().hex,
43 'domain': self.project_domain_id,
44 'description': uuid.uuid4().hex}
45
46 group = self.client.groups.create(**group_ref)
47 self.addCleanup(self.client.groups.delete, group)
48 self.check_group(group, group_ref)
49
50 def test_get_group(self):
51 group = fixtures.Group(self.client, self.project_domain_id)
52 self.useFixture(group)
53
54 group_ret = self.client.groups.get(group.id)
55 self.check_group(group_ret, group.ref)
56
57 def test_list_groups(self):
58 group_one = fixtures.Group(self.client, self.project_domain_id)
59 self.useFixture(group_one)
60
61 group_two = fixtures.Group(self.client, self.project_domain_id)
62 self.useFixture(group_two)
63
64 groups = self.client.groups.list()
65
66 # All groups are valid
67 for group in groups:
68 self.check_group(group)
69
70 self.assertIn(group_one.entity, groups)
71 self.assertIn(group_two.entity, groups)
72
73 def test_update_group(self):
74 group = fixtures.Group(self.client, self.project_domain_id)
75 self.useFixture(group)
76
77 new_name = fixtures.RESOURCE_NAME_PREFIX + uuid.uuid4().hex
78 new_description = uuid.uuid4().hex
79
80 group_ret = self.client.groups.update(group.id,
81 name=new_name,
82 description=new_description)
83
84 group.ref.update({'name': new_name, 'description': new_description})
85 self.check_group(group_ret, group.ref)
86
87 def test_delete_group(self):
88 group = self.client.groups.create(name=uuid.uuid4().hex,
89 domain=self.project_domain_id)
90
91 self.client.groups.delete(group.id)
92 self.assertRaises(http.NotFound,
93 self.client.groups.get,
94 group.id)