blob: 960e2cb12571ab6e5e16b94d9ba9b764653163a4 [file] [log] [blame]
harika-vakadi40e10112013-02-08 14:38:09 +05301# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.identity import base
Ken'ichi Ohmichi7bd25752017-03-10 10:45:39 -080017from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080018from tempest.lib import decorators
harika-vakadi40e10112013-02-08 14:38:09 +053019
20
Matthew Treinishdb2c5972014-01-31 22:18:59 +000021class PoliciesTestJSON(base.BaseIdentityV3AdminTest):
harika-vakadi40e10112013-02-08 14:38:09 +053022
23 def _delete_policy(self, policy_id):
Yaroslav Lobankoved4d15c2015-12-18 11:30:10 +030024 self.policies_client.delete_policy(policy_id)
harika-vakadi40e10112013-02-08 14:38:09 +053025
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080026 @decorators.idempotent_id('1a0ad286-2d06-4123-ab0d-728893a76201')
harika-vakadi40e10112013-02-08 14:38:09 +053027 def test_list_policies(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020028 # Test to list policies
harika-vakadi40e10112013-02-08 14:38:09 +053029 policy_ids = list()
30 fetched_ids = list()
31 for _ in range(3):
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000032 blob = data_utils.rand_name('BlobName')
33 policy_type = data_utils.rand_name('PolicyType')
Yaroslav Lobankoved4d15c2015-12-18 11:30:10 +030034 policy = self.policies_client.create_policy(
Yaroslav Lobankov5918c452015-11-11 16:03:12 +030035 blob=blob, type=policy_type)['policy']
harika-vakadi40e10112013-02-08 14:38:09 +053036 # Delete the Policy at the end of this method
37 self.addCleanup(self._delete_policy, policy['id'])
38 policy_ids.append(policy['id'])
39 # List and Verify Policies
Yaroslav Lobankoved4d15c2015-12-18 11:30:10 +030040 body = self.policies_client.list_policies()['policies']
harika-vakadi40e10112013-02-08 14:38:09 +053041 for p in body:
42 fetched_ids.append(p['id'])
43 missing_pols = [p for p in policy_ids if p not in fetched_ids]
Masayuki Igawaf9009b42017-04-10 14:49:29 +090044 self.assertEmpty(missing_pols)
harika-vakadi40e10112013-02-08 14:38:09 +053045
Jordan Pittier3b46d272017-04-12 16:17:28 +020046 @decorators.attr(type='smoke')
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080047 @decorators.idempotent_id('e544703a-2f03-4cf2-9b0f-350782fdb0d3')
harika-vakadi40e10112013-02-08 14:38:09 +053048 def test_create_update_delete_policy(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020049 # Test to update policy
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000050 blob = data_utils.rand_name('BlobName')
51 policy_type = data_utils.rand_name('PolicyType')
Yaroslav Lobankoved4d15c2015-12-18 11:30:10 +030052 policy = self.policies_client.create_policy(blob=blob,
53 type=policy_type)['policy']
harika-vakadi40e10112013-02-08 14:38:09 +053054 self.addCleanup(self._delete_policy, policy['id'])
55 self.assertIn('id', policy)
56 self.assertIn('type', policy)
57 self.assertIn('blob', policy)
58 self.assertIsNotNone(policy['id'])
59 self.assertEqual(blob, policy['blob'])
60 self.assertEqual(policy_type, policy['type'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020061 # Update policy
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000062 update_type = data_utils.rand_name('UpdatedPolicyType')
Yaroslav Lobankoved4d15c2015-12-18 11:30:10 +030063 data = self.policies_client.update_policy(
John Warren7d314722015-08-13 13:15:11 +000064 policy['id'], type=update_type)['policy']
Attila Fazekase191cb12013-07-29 06:41:52 +020065 self.assertIn('type', data)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020066 # Assertion for updated value with fetched value
Yaroslav Lobankoved4d15c2015-12-18 11:30:10 +030067 fetched_policy = self.policies_client.show_policy(
68 policy['id'])['policy']
harika-vakadi40e10112013-02-08 14:38:09 +053069 self.assertIn('id', fetched_policy)
70 self.assertIn('blob', fetched_policy)
71 self.assertIn('type', fetched_policy)
72 self.assertEqual(fetched_policy['id'], policy['id'])
73 self.assertEqual(fetched_policy['blob'], policy['blob'])
74 self.assertEqual(update_type, fetched_policy['type'])