ravikumar-venkatesan | acf99d7 | 2014-07-09 14:58:25 +0000 | [diff] [blame^] | 1 | # Copyright 2014 Hewlett-Packard Development Company, L.P |
ravikumar-venkatesan | 3052e94 | 2014-05-12 18:25:17 +0000 | [diff] [blame] | 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 |
| 17 | from tempest.common.utils import data_utils |
| 18 | from tempest import exceptions |
| 19 | from tempest import test |
| 20 | |
| 21 | |
| 22 | class 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): |
| 43 | resp, _ = self.client.delete_region(region_id) |
| 44 | self.assertEqual(204, resp.status) |
| 45 | self.assertRaises(exceptions.NotFound, |
| 46 | self.client.get_region, region_id) |
| 47 | |
| 48 | @test.attr(type='gate') |
| 49 | def test_create_update_get_delete_region(self): |
| 50 | r_description = data_utils.rand_name('description-') |
| 51 | resp, region = self.client.create_region( |
| 52 | r_description, parent_region_id=self.setup_regions[0]['id']) |
| 53 | self.assertEqual(201, resp.status) |
| 54 | self.addCleanup(self._delete_region, region['id']) |
| 55 | self.assertEqual(r_description, region['description']) |
| 56 | self.assertEqual(self.setup_regions[0]['id'], |
| 57 | region['parent_region_id']) |
| 58 | # Update region with new description and parent ID |
| 59 | r_alt_description = data_utils.rand_name('description-') |
| 60 | resp, region = self.client.update_region( |
| 61 | region['id'], |
| 62 | description=r_alt_description, |
| 63 | parent_region_id=self.setup_regions[1]['id']) |
| 64 | self.assertEqual(200, resp.status) |
| 65 | self.assertEqual(r_alt_description, region['description']) |
| 66 | self.assertEqual(self.setup_regions[1]['id'], |
| 67 | region['parent_region_id']) |
| 68 | # Get the details of region |
| 69 | resp, region = self.client.get_region(region['id']) |
| 70 | self.assertEqual(200, resp.status) |
| 71 | self.assertEqual(r_alt_description, region['description']) |
| 72 | self.assertEqual(self.setup_regions[1]['id'], |
| 73 | region['parent_region_id']) |
| 74 | |
| 75 | @test.attr(type='smoke') |
| 76 | def test_create_region_with_specific_id(self): |
| 77 | # Create a region with a specific id |
| 78 | r_region_id = data_utils.rand_uuid() |
| 79 | r_description = data_utils.rand_name('description-') |
| 80 | resp, region = self.client.create_region( |
| 81 | r_description, unique_region_id=r_region_id) |
| 82 | self.addCleanup(self._delete_region, region['id']) |
| 83 | # Asserting Create Region with specific id response body |
| 84 | self.assertEqual(201, resp.status) |
| 85 | self.assertEqual(r_region_id, region['id']) |
| 86 | self.assertEqual(r_description, region['description']) |
| 87 | |
| 88 | @test.attr(type='gate') |
| 89 | def test_list_regions(self): |
| 90 | # Get a list of regions |
| 91 | resp, fetched_regions = self.client.list_regions() |
| 92 | self.assertEqual(200, resp.status) |
| 93 | missing_regions =\ |
| 94 | [e for e in self.setup_regions if e not in fetched_regions] |
| 95 | # Asserting List Regions response |
| 96 | self.assertEqual(0, len(missing_regions), |
| 97 | "Failed to find region %s in fetched list" % |
| 98 | ', '.join(str(e) for e in missing_regions)) |
| 99 | |
| 100 | |
| 101 | class RegionsTestXML(RegionsTestJSON): |
| 102 | _interface = 'xml' |