Debian Codegraph @

keystoneclient/tests/functional/v3/test_policies.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
17 from keystoneclient.tests.functional import base
18 from keystoneclient.tests.functional.v3 import client_fixtures as fixtures
19
20
21 class PoliciesTestCase(base.V3ClientTestCase):
22
23 def check_policy(self, policy, policy_ref=None):
24 self.assertIsNotNone(policy.id)
25 self.assertIn('self', policy.links)
26 self.assertIn('/policies/' + policy.id, policy.links['self'])
27
28 if policy_ref:
29 self.assertEqual(policy_ref['blob'], policy.blob)
30 self.assertEqual(policy_ref['type'], policy.type)
31
32 else:
33 # Only check remaining mandatory attributes
34 self.assertIsNotNone(policy.blob)
35 self.assertIsNotNone(policy.type)
36
37 def test_create_policy(self):
38 policy_ref = {'blob': uuid.uuid4().hex,
39 'type': uuid.uuid4().hex}
40
41 policy = self.client.policies.create(**policy_ref)
42 self.addCleanup(self.client.policies.delete, policy)
43 self.check_policy(policy, policy_ref)
44
45 def test_get_policy(self):
46 policy = fixtures.Policy(self.client)
47 self.useFixture(policy)
48
49 policy_ret = self.client.policies.get(policy.id)
50 self.check_policy(policy_ret, policy.ref)
51
52 def test_list_policies(self):
53 policy_one = fixtures.Policy(self.client)
54 self.useFixture(policy_one)
55
56 policy_two = fixtures.Policy(self.client)
57 self.useFixture(policy_two)
58
59 policies = self.client.policies.list()
60
61 # All policies are valid
62 for policy in policies:
63 self.check_policy(policy)
64
65 self.assertIn(policy_one.entity, policies)
66 self.assertIn(policy_two.entity, policies)
67
68 def test_update_policy(self):
69 policy = fixtures.Policy(self.client)
70 self.useFixture(policy)
71
72 new_blob = uuid.uuid4().hex
73 new_type = uuid.uuid4().hex
74
75 policy_ret = self.client.policies.update(policy.id,
76 blob=new_blob,
77 type=new_type)
78
79 policy.ref.update({'blob': new_blob, 'type': new_type})
80 self.check_policy(policy_ret, policy.ref)
81
82 def test_delete_policy(self):
83 policy = self.client.policies.create(blob=uuid.uuid4().hex,
84 type=uuid.uuid4().hex)
85
86 self.client.policies.delete(policy.id)
87 self.assertRaises(http.NotFound,
88 self.client.policies.get,
89 policy.id)