harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 OpenStack Foundation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
| 18 | from tempest.api.identity import base |
| 19 | from tempest.common.utils.data_utils import rand_name |
| 20 | from tempest.test import attr |
| 21 | |
| 22 | |
| 23 | class PoliciesTestJSON(base.BaseIdentityAdminTest): |
| 24 | _interface = 'json' |
| 25 | |
| 26 | def _delete_policy(self, policy_id): |
| 27 | resp, _ = self.policy_client.delete_policy(policy_id) |
| 28 | self.assertEqual(204, resp.status) |
| 29 | |
| 30 | @attr(type='smoke') |
| 31 | def test_list_policies(self): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame^] | 32 | # Test to list policies |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 33 | policy_ids = list() |
| 34 | fetched_ids = list() |
| 35 | for _ in range(3): |
| 36 | blob = rand_name('BlobName-') |
| 37 | policy_type = rand_name('PolicyType-') |
| 38 | resp, policy = self.policy_client.create_policy(blob, |
| 39 | policy_type) |
| 40 | # Delete the Policy at the end of this method |
| 41 | self.addCleanup(self._delete_policy, policy['id']) |
| 42 | policy_ids.append(policy['id']) |
| 43 | # List and Verify Policies |
| 44 | resp, body = self.policy_client.list_policies() |
| 45 | self.assertEqual(resp['status'], '200') |
| 46 | for p in body: |
| 47 | fetched_ids.append(p['id']) |
| 48 | missing_pols = [p for p in policy_ids if p not in fetched_ids] |
| 49 | self.assertEqual(0, len(missing_pols)) |
| 50 | |
| 51 | @attr(type='smoke') |
| 52 | def test_create_update_delete_policy(self): |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame^] | 53 | # Test to update policy |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 54 | blob = rand_name('BlobName-') |
| 55 | policy_type = rand_name('PolicyType-') |
| 56 | resp, policy = self.policy_client.create_policy(blob, policy_type) |
| 57 | self.addCleanup(self._delete_policy, policy['id']) |
| 58 | self.assertIn('id', policy) |
| 59 | self.assertIn('type', policy) |
| 60 | self.assertIn('blob', policy) |
| 61 | self.assertIsNotNone(policy['id']) |
| 62 | self.assertEqual(blob, policy['blob']) |
| 63 | self.assertEqual(policy_type, policy['type']) |
| 64 | resp, fetched_policy = self.policy_client.get_policy(policy['id']) |
| 65 | self.assertEqual(resp['status'], '200') |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame^] | 66 | # Update policy |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 67 | update_type = rand_name('UpdatedPolicyType-') |
| 68 | resp, data = self.policy_client.update_policy( |
| 69 | policy['id'], type=update_type) |
Attila Fazekas | e191cb1 | 2013-07-29 06:41:52 +0200 | [diff] [blame] | 70 | self.assertIn('type', data) |
Attila Fazekas | f7f34f9 | 2013-08-01 17:01:44 +0200 | [diff] [blame^] | 71 | # Assertion for updated value with fetched value |
harika-vakadi | 40e1011 | 2013-02-08 14:38:09 +0530 | [diff] [blame] | 72 | resp, fetched_policy = self.policy_client.get_policy(policy['id']) |
| 73 | self.assertIn('id', fetched_policy) |
| 74 | self.assertIn('blob', fetched_policy) |
| 75 | self.assertIn('type', fetched_policy) |
| 76 | self.assertEqual(fetched_policy['id'], policy['id']) |
| 77 | self.assertEqual(fetched_policy['blob'], policy['blob']) |
| 78 | self.assertEqual(update_type, fetched_policy['type']) |
| 79 | |
| 80 | |
| 81 | class PoliciesTestXML(PoliciesTestJSON): |
| 82 | _interface = 'xml' |