harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 1 | # 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 | |
| 16 | from tempest.api.identity import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame^] | 18 | from tempest.lib import decorators |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 19 | from tempest import test |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 20 | |
| 21 | |
Matthew Treinish | db2c597 | 2014-01-31 22:18:59 +0000 | [diff] [blame] | 22 | class PoliciesTestJSON(base.BaseIdentityV3AdminTest): |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 23 | |
| 24 | def _delete_policy(self, policy_id): |
Yaroslav Lobankov | ed4d15c | 2015-12-18 11:30:10 +0300 | [diff] [blame] | 25 | self.policies_client.delete_policy(policy_id) |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 26 | |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame^] | 27 | @decorators.idempotent_id('1a0ad286-2d06-4123-ab0d-728893a76201') |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 28 | def test_list_policies(self): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 29 | # Test to list policies |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 30 | policy_ids = list() |
| 31 | fetched_ids = list() |
| 32 | for _ in range(3): |
Ken'ichi Ohmichi | 9650847 | 2015-03-23 01:43:42 +0000 | [diff] [blame] | 33 | blob = data_utils.rand_name('BlobName') |
| 34 | policy_type = data_utils.rand_name('PolicyType') |
Yaroslav Lobankov | ed4d15c | 2015-12-18 11:30:10 +0300 | [diff] [blame] | 35 | policy = self.policies_client.create_policy( |
Yaroslav Lobankov | 5918c45 | 2015-11-11 16:03:12 +0300 | [diff] [blame] | 36 | blob=blob, type=policy_type)['policy'] |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 37 | # Delete the Policy at the end of this method |
| 38 | self.addCleanup(self._delete_policy, policy['id']) |
| 39 | policy_ids.append(policy['id']) |
| 40 | # List and Verify Policies |
Yaroslav Lobankov | ed4d15c | 2015-12-18 11:30:10 +0300 | [diff] [blame] | 41 | body = self.policies_client.list_policies()['policies'] |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 42 | for p in body: |
| 43 | fetched_ids.append(p['id']) |
| 44 | missing_pols = [p for p in policy_ids if p not in fetched_ids] |
| 45 | self.assertEqual(0, len(missing_pols)) |
| 46 | |
Matthew Treinish | 5c660ab | 2014-05-18 21:14:36 -0400 | [diff] [blame] | 47 | @test.attr(type='smoke') |
Ken'ichi Ohmichi | eeabdd2 | 2017-01-27 17:46:00 -0800 | [diff] [blame^] | 48 | @decorators.idempotent_id('e544703a-2f03-4cf2-9b0f-350782fdb0d3') |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 49 | def test_create_update_delete_policy(self): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 50 | # Test to update policy |
Ken'ichi Ohmichi | 9650847 | 2015-03-23 01:43:42 +0000 | [diff] [blame] | 51 | blob = data_utils.rand_name('BlobName') |
| 52 | policy_type = data_utils.rand_name('PolicyType') |
Yaroslav Lobankov | ed4d15c | 2015-12-18 11:30:10 +0300 | [diff] [blame] | 53 | policy = self.policies_client.create_policy(blob=blob, |
| 54 | type=policy_type)['policy'] |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 55 | 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 Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 62 | # Update policy |
Ken'ichi Ohmichi | 9650847 | 2015-03-23 01:43:42 +0000 | [diff] [blame] | 63 | update_type = data_utils.rand_name('UpdatedPolicyType') |
Yaroslav Lobankov | ed4d15c | 2015-12-18 11:30:10 +0300 | [diff] [blame] | 64 | data = self.policies_client.update_policy( |
John Warren | 7d31472 | 2015-08-13 13:15:11 +0000 | [diff] [blame] | 65 | policy['id'], type=update_type)['policy'] |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 66 | self.assertIn('type', data) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame] | 67 | # Assertion for updated value with fetched value |
Yaroslav Lobankov | ed4d15c | 2015-12-18 11:30:10 +0300 | [diff] [blame] | 68 | fetched_policy = self.policies_client.show_policy( |
| 69 | policy['id'])['policy'] |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 70 | self.assertIn('id', fetched_policy) |
| 71 | self.assertIn('blob', fetched_policy) |
| 72 | self.assertIn('type', fetched_policy) |
| 73 | self.assertEqual(fetched_policy['id'], policy['id']) |
| 74 | self.assertEqual(fetched_policy['blob'], policy['blob']) |
| 75 | self.assertEqual(update_type, fetched_policy['type']) |