blob: 8fc0e22fc5872f4139652eb9711dd9c7b25dd9b9 [file] [log] [blame]
ravikumar-venkatesanacf99d72014-07-09 14:58:25 +00001# Copyright 2014 Hewlett-Packard Development Company, L.P
ravikumar-venkatesan3052e942014-05-12 18:25:17 +00002# 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
16from tempest.api.identity import base
17from tempest.common.utils import data_utils
18from tempest import exceptions
19from tempest import test
20
21
22class RegionsTestJSON(base.BaseIdentityV3AdminTest):
23 _interface = 'json'
24
25 @classmethod
26 @test.safe_setup
27 def setUpClass(cls):
28 super(RegionsTestJSON, cls).setUpClass()
29 cls.setup_regions = list()
30 cls.client = cls.region_client
31 for i in range(2):
32 r_description = data_utils.rand_name('description-')
33 _, region = cls.client.create_region(r_description)
34 cls.setup_regions.append(region)
35
36 @classmethod
37 def tearDownClass(cls):
38 for r in cls.setup_regions:
39 cls.client.delete_region(r['id'])
40 super(RegionsTestJSON, cls).tearDownClass()
41
42 def _delete_region(self, region_id):
David Kranz2aaf5312014-08-29 09:22:10 -040043 self.client.delete_region(region_id)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000044 self.assertRaises(exceptions.NotFound,
45 self.client.get_region, region_id)
46
47 @test.attr(type='gate')
48 def test_create_update_get_delete_region(self):
49 r_description = data_utils.rand_name('description-')
David Kranz2aaf5312014-08-29 09:22:10 -040050 _, region = self.client.create_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000051 r_description, parent_region_id=self.setup_regions[0]['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000052 self.addCleanup(self._delete_region, region['id'])
53 self.assertEqual(r_description, region['description'])
54 self.assertEqual(self.setup_regions[0]['id'],
55 region['parent_region_id'])
56 # Update region with new description and parent ID
57 r_alt_description = data_utils.rand_name('description-')
David Kranz2aaf5312014-08-29 09:22:10 -040058 _, region = self.client.update_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000059 region['id'],
60 description=r_alt_description,
61 parent_region_id=self.setup_regions[1]['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000062 self.assertEqual(r_alt_description, region['description'])
63 self.assertEqual(self.setup_regions[1]['id'],
64 region['parent_region_id'])
65 # Get the details of region
David Kranz2aaf5312014-08-29 09:22:10 -040066 _, region = self.client.get_region(region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000067 self.assertEqual(r_alt_description, region['description'])
68 self.assertEqual(self.setup_regions[1]['id'],
69 region['parent_region_id'])
70
71 @test.attr(type='smoke')
72 def test_create_region_with_specific_id(self):
73 # Create a region with a specific id
74 r_region_id = data_utils.rand_uuid()
75 r_description = data_utils.rand_name('description-')
David Kranz2aaf5312014-08-29 09:22:10 -040076 _, region = self.client.create_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000077 r_description, unique_region_id=r_region_id)
78 self.addCleanup(self._delete_region, region['id'])
79 # Asserting Create Region with specific id response body
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000080 self.assertEqual(r_region_id, region['id'])
81 self.assertEqual(r_description, region['description'])
82
83 @test.attr(type='gate')
84 def test_list_regions(self):
85 # Get a list of regions
David Kranz2aaf5312014-08-29 09:22:10 -040086 _, fetched_regions = self.client.list_regions()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000087 missing_regions =\
88 [e for e in self.setup_regions if e not in fetched_regions]
89 # Asserting List Regions response
90 self.assertEqual(0, len(missing_regions),
91 "Failed to find region %s in fetched list" %
92 ', '.join(str(e) for e in missing_regions))
93
94
95class RegionsTestXML(RegionsTestJSON):
96 _interface = 'xml'