Debian Codegraph @

keystoneclient/tests/unit/v3/test_groups.py

raw symbols SCIP
1 # Copyright 2012 OpenStack Foundation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 import uuid
16
17 from keystoneclient.tests.unit.v3 import utils
18 from keystoneclient.v3 import groups
19
20
21 class GroupTests(utils.ClientTestCase, utils.CrudTests):
22 def setUp(self):
23 super(GroupTests, self).setUp()
24 self.key = 'group'
25 self.collection_key = 'groups'
26 self.model = groups.Group
27 self.manager = self.client.groups
28
29 def new_ref(self, **kwargs):
30 kwargs = super(GroupTests, self).new_ref(**kwargs)
31 kwargs.setdefault('name', uuid.uuid4().hex)
32 return kwargs
33
34 def test_list_groups_for_user(self):
35 user_id = uuid.uuid4().hex
36 ref_list = [self.new_ref(), self.new_ref()]
37
38 self.stub_entity('GET',
39 ['users', user_id, self.collection_key],
40 status_code=200, entity=ref_list)
41
42 returned_list = self.manager.list(user=user_id)
43 self.assertEqual(len(ref_list), len(returned_list))
44 [self.assertIsInstance(r, self.model) for r in returned_list]
45
46 def test_list_groups_for_domain(self):
47 ref_list = [self.new_ref(), self.new_ref()]
48 domain_id = uuid.uuid4().hex
49
50 self.stub_entity('GET',
51 [self.collection_key],
52 status_code=200, entity=ref_list)
53
54 returned_list = self.manager.list(domain=domain_id)
55 self.assertTrue(len(ref_list), len(returned_list))
56 [self.assertIsInstance(r, self.model) for r in returned_list]
57
58 self.assertQueryStringIs('domain_id=%s' % domain_id)