blob: 2fbef7747cdf10f7d01e61a6b86a3a7f618124ae [file] [log] [blame]
nayna-patel4df72dc2013-05-29 10:27:24 +00001# 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
nayna-patel049e1572013-06-19 09:22:35 +000018
nayna-patel4df72dc2013-05-29 10:27:24 +000019from tempest.api.identity import base
20from tempest.common.utils.data_utils import rand_name
21from tempest.test import attr
22
23
24class DomainsTestJSON(base.BaseIdentityAdminTest):
25 _interface = 'json'
26
27 def _delete_domain(self, domain_id):
Chang Bo Guof099f802013-09-13 19:01:46 -070028 # It is necessary to disable the domain before deleting,
nayna-patel4df72dc2013-05-29 10:27:24 +000029 # or else it would result in unauthorized error
30 _, body = self.v3_client.update_domain(domain_id, enabled=False)
31 resp, _ = self.v3_client.delete_domain(domain_id)
32 self.assertEqual(204, resp.status)
33
34 @attr(type='smoke')
35 def test_list_domains(self):
Attila Fazekasf7f34f92013-08-01 17:01:44 +020036 # Test to list domains
nayna-patel4df72dc2013-05-29 10:27:24 +000037 domain_ids = list()
38 fetched_ids = list()
39 for _ in range(3):
40 _, domain = self.v3_client.create_domain(
41 rand_name('domain-'), description=rand_name('domain-desc-'))
Chang Bo Guof099f802013-09-13 19:01:46 -070042 # Delete the domain at the end of this method
nayna-patel4df72dc2013-05-29 10:27:24 +000043 self.addCleanup(self._delete_domain, domain['id'])
44 domain_ids.append(domain['id'])
45 # List and Verify Domains
46 resp, body = self.v3_client.list_domains()
47 self.assertEqual(resp['status'], '200')
48 for d in body:
49 fetched_ids.append(d['id'])
50 missing_doms = [d for d in domain_ids if d not in fetched_ids]
51 self.assertEqual(0, len(missing_doms))
52
nayna-patel049e1572013-06-19 09:22:35 +000053 @attr(type='smoke')
54 def test_create_update_delete_domain(self):
55 d_name = rand_name('domain-')
56 d_desc = rand_name('domain-desc-')
57 resp_1, domain = self.v3_client.create_domain(
58 d_name, description=d_desc)
59 self.assertEqual(resp_1['status'], '201')
60 self.addCleanup(self._delete_domain, domain['id'])
61 self.assertIn('id', domain)
62 self.assertIn('description', domain)
63 self.assertIn('name', domain)
64 self.assertIn('enabled', domain)
65 self.assertIn('links', domain)
66 self.assertIsNotNone(domain['id'])
67 self.assertEqual(d_name, domain['name'])
68 self.assertEqual(d_desc, domain['description'])
69 if self._interface == "json":
70 self.assertEqual(True, domain['enabled'])
71 else:
72 self.assertEqual('true', str(domain['enabled']).lower())
73 new_desc = rand_name('new-desc-')
74 new_name = rand_name('new-name-')
75
76 resp_2, updated_domain = self.v3_client.update_domain(
77 domain['id'], name=new_name, description=new_desc)
78 self.assertEqual(resp_2['status'], '200')
79 self.assertIn('id', updated_domain)
80 self.assertIn('description', updated_domain)
81 self.assertIn('name', updated_domain)
82 self.assertIn('enabled', updated_domain)
83 self.assertIn('links', updated_domain)
84 self.assertIsNotNone(updated_domain['id'])
85 self.assertEqual(new_name, updated_domain['name'])
86 self.assertEqual(new_desc, updated_domain['description'])
87 self.assertEqual('true', str(updated_domain['enabled']).lower())
88
89 resp_3, fetched_domain = self.v3_client.get_domain(domain['id'])
90 self.assertEqual(resp_3['status'], '200')
91 self.assertEqual(new_name, fetched_domain['name'])
92 self.assertEqual(new_desc, fetched_domain['description'])
93 self.assertEqual('true', str(fetched_domain['enabled']).lower())
94
nayna-patel4df72dc2013-05-29 10:27:24 +000095
96class DomainsTestXML(DomainsTestJSON):
97 _interface = 'xml'