blob: 737a0e04618ed4943617ee86bc5fbe1a8f58df45 [file] [log] [blame]
harika-vakadi40e10112013-02-08 14:38:09 +05301# 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
18from tempest.api.identity import base
19from tempest.common.utils.data_utils import rand_name
20from tempest.test import attr
21
22
23class 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 Fazekasf7f34f92013-08-01 17:01:44 +020032 # Test to list policies
harika-vakadi40e10112013-02-08 14:38:09 +053033 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 Fazekasf7f34f92013-08-01 17:01:44 +020053 # Test to update policy
harika-vakadi40e10112013-02-08 14:38:09 +053054 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 Fazekasf7f34f92013-08-01 17:01:44 +020066 # Update policy
harika-vakadi40e10112013-02-08 14:38:09 +053067 update_type = rand_name('UpdatedPolicyType-')
68 resp, data = self.policy_client.update_policy(
69 policy['id'], type=update_type)
Attila Fazekase191cb12013-07-29 06:41:52 +020070 self.assertIn('type', data)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020071 # Assertion for updated value with fetched value
harika-vakadi40e10112013-02-08 14:38:09 +053072 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
81class PoliciesTestXML(PoliciesTestJSON):
82 _interface = 'xml'