blob: 63d2b0db17861763da5696335425c6a11beedaaa [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
17
harika-vakadi40e10112013-02-08 14:38:09 +053018from tempest.api.identity import base
Matthew Treinish5c660ab2014-05-18 21:14:36 -040019from tempest import test
harika-vakadi40e10112013-02-08 14:38:09 +053020
21
Matthew Treinishdb2c5972014-01-31 22:18:59 +000022class PoliciesTestJSON(base.BaseIdentityV3AdminTest):
harika-vakadi40e10112013-02-08 14:38:09 +053023
24 def _delete_policy(self, policy_id):
David Kranz2aaf5312014-08-29 09:22:10 -040025 self.policy_client.delete_policy(policy_id)
harika-vakadi40e10112013-02-08 14:38:09 +053026
Matthew Treinish5c660ab2014-05-18 21:14:36 -040027 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080028 @test.idempotent_id('1a0ad286-2d06-4123-ab0d-728893a76201')
harika-vakadi40e10112013-02-08 14:38:09 +053029 def test_list_policies(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020030 # Test to list policies
harika-vakadi40e10112013-02-08 14:38:09 +053031 policy_ids = list()
32 fetched_ids = list()
33 for _ in range(3):
Masayuki Igawa259c1132013-10-31 17:48:44 +090034 blob = data_utils.rand_name('BlobName-')
35 policy_type = data_utils.rand_name('PolicyType-')
David Kranz70f137c2014-10-23 17:57:18 -040036 policy = self.policy_client.create_policy(blob,
37 policy_type)
harika-vakadi40e10112013-02-08 14:38:09 +053038 # Delete the Policy at the end of this method
39 self.addCleanup(self._delete_policy, policy['id'])
40 policy_ids.append(policy['id'])
41 # List and Verify Policies
David Kranz291bf792014-12-02 10:31:40 -050042 body = self.policy_client.list_policies()
harika-vakadi40e10112013-02-08 14:38:09 +053043 for p in body:
44 fetched_ids.append(p['id'])
45 missing_pols = [p for p in policy_ids if p not in fetched_ids]
46 self.assertEqual(0, len(missing_pols))
47
Matthew Treinish5c660ab2014-05-18 21:14:36 -040048 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080049 @test.idempotent_id('e544703a-2f03-4cf2-9b0f-350782fdb0d3')
harika-vakadi40e10112013-02-08 14:38:09 +053050 def test_create_update_delete_policy(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020051 # Test to update policy
Masayuki Igawa259c1132013-10-31 17:48:44 +090052 blob = data_utils.rand_name('BlobName-')
53 policy_type = data_utils.rand_name('PolicyType-')
David Kranz70f137c2014-10-23 17:57:18 -040054 policy = self.policy_client.create_policy(blob, policy_type)
harika-vakadi40e10112013-02-08 14:38:09 +053055 self.addCleanup(self._delete_policy, policy['id'])
56 self.assertIn('id', policy)
57 self.assertIn('type', policy)
58 self.assertIn('blob', policy)
59 self.assertIsNotNone(policy['id'])
60 self.assertEqual(blob, policy['blob'])
61 self.assertEqual(policy_type, policy['type'])
Attila Fazekasf7f34f92013-08-01 17:01:44 +020062 # Update policy
Masayuki Igawa259c1132013-10-31 17:48:44 +090063 update_type = data_utils.rand_name('UpdatedPolicyType-')
David Kranz291bf792014-12-02 10:31:40 -050064 data = self.policy_client.update_policy(
harika-vakadi40e10112013-02-08 14:38:09 +053065 policy['id'], type=update_type)
Attila Fazekase191cb12013-07-29 06:41:52 +020066 self.assertIn('type', data)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020067 # Assertion for updated value with fetched value
David Kranz291bf792014-12-02 10:31:40 -050068 fetched_policy = self.policy_client.get_policy(policy['id'])
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'])