Debian Codegraph @

keystoneclient/tests/functional/v3/test_domains.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 DomainsTestCase(base.V3ClientTestCase):
21
22 def check_domain(self, domain, domain_ref=None):
23 self.assertIsNotNone(domain.id)
24 self.assertIn('self', domain.links)
25 self.assertIn('/domains/' + domain.id, domain.links['self'])
26
27 if domain_ref:
28 self.assertEqual(domain_ref['name'], domain.name)
29 self.assertEqual(domain_ref['enabled'], domain.enabled)
30
31 # There is no guarantee description is present in domain
32 if hasattr(domain_ref, 'description'):
33 self.assertEqual(domain_ref['description'], domain.description)
34 else:
35 # Only check remaining mandatory attributes
36 self.assertIsNotNone(domain.name)
37 self.assertIsNotNone(domain.enabled)
38
39 def test_create_domain(self):
40 domain_ref = {
41 'name': fixtures.RESOURCE_NAME_PREFIX + uuid.uuid4().hex,
42 'description': uuid.uuid4().hex,
43 'enabled': True}
44 domain = self.client.domains.create(**domain_ref)
45 self.check_domain(domain, domain_ref)
46
47 # Only disabled domains can be deleted
48 self.addCleanup(self.client.domains.delete, domain)
49 self.addCleanup(self.client.domains.update, domain, enabled=False)
50
51 def test_get_domain(self):
52 domain_id = self.project_domain_id
53 domain_ret = self.client.domains.get(domain_id)
54 self.check_domain(domain_ret)
55
56 def test_list_domains(self):
57 domain_one = fixtures.Domain(self.client)
58 self.useFixture(domain_one)
59
60 domain_two = fixtures.Domain(self.client)
61 self.useFixture(domain_two)
62
63 domains = self.client.domains.list()
64
65 # All domains are valid
66 for domain in domains:
67 self.check_domain(domain)
68
69 self.assertIn(domain_one.entity, domains)
70 self.assertIn(domain_two.entity, domains)
71
72 def test_update_domain(self):
73 domain = fixtures.Domain(self.client)
74 self.useFixture(domain)
75
76 new_description = uuid.uuid4().hex
77 domain_ret = self.client.domains.update(domain.id,
78 description=new_description)
79
80 domain.ref.update({'description': new_description})
81 self.check_domain(domain_ret, domain.ref)
82
83 def test_delete_domain(self):
84 domain = self.client.domains.create(name=uuid.uuid4().hex,
85 description=uuid.uuid4().hex,
86 enabled=True)
87
88 # Only disabled domains can be deleted
89 self.assertRaises(http.Forbidden,
90 self.client.domains.delete,
91 domain.id)
92
93 self.client.domains.update(domain, enabled=False)
94 self.client.domains.delete(domain.id)
95 self.assertRaises(http.NotFound,
96 self.client.domains.get,
97 domain.id)