summaryrefslogtreecommitdiff
path: root/tempest/api/identity/admin/v3/test_regions.py
blob: ac550a73aef68e0e52565e18264f6ea0529d8e5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Copyright 2014 Hewlett-Packard Development Company, L.P
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

from tempest.api.identity import base
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators


class RegionsTestJSON(base.BaseIdentityV3AdminTest):

    @classmethod
    def setup_clients(cls):
        super(RegionsTestJSON, cls).setup_clients()
        cls.client = cls.regions_client

    @classmethod
    def resource_setup(cls):
        super(RegionsTestJSON, cls).resource_setup()
        cls.setup_regions = list()
        for _ in range(2):
            r_description = data_utils.rand_name('description')
            region = cls.client.create_region(
                description=r_description)['region']
            cls.setup_regions.append(region)

    @classmethod
    def resource_cleanup(cls):
        for r in cls.setup_regions:
            cls.client.delete_region(r['id'])
        super(RegionsTestJSON, cls).resource_cleanup()

    @decorators.idempotent_id('56186092-82e4-43f2-b954-91013218ba42')
    def test_create_update_get_delete_region(self):
        # Create region
        r_description = data_utils.rand_name('description')
        region = self.client.create_region(
            description=r_description,
            parent_region_id=self.setup_regions[0]['id'])['region']
        # This test will delete the region as part of the validation
        # procedure, so it needs a different cleanup method that
        # would be useful in case the tests fails at any point before
        # reaching the deletion part.
        self.addCleanup(test_utils.call_and_ignore_notfound_exc,
                        self.client.delete_region, region['id'])
        self.assertEqual(r_description, region['description'])
        self.assertEqual(self.setup_regions[0]['id'],
                         region['parent_region_id'])
        # Update region with new description and parent ID
        r_alt_description = data_utils.rand_name('description')
        region = self.client.update_region(
            region['id'],
            description=r_alt_description,
            parent_region_id=self.setup_regions[1]['id'])['region']
        self.assertEqual(r_alt_description, region['description'])
        self.assertEqual(self.setup_regions[1]['id'],
                         region['parent_region_id'])
        # Get the details of region
        region = self.client.show_region(region['id'])['region']
        self.assertEqual(r_alt_description, region['description'])
        self.assertEqual(self.setup_regions[1]['id'],
                         region['parent_region_id'])
        # Delete the region
        self.client.delete_region(region['id'])
        body = self.client.list_regions()['regions']
        regions_list = [r['id'] for r in body]
        self.assertNotIn(region['id'], regions_list)

    @decorators.attr(type='smoke')
    @decorators.idempotent_id('2c12c5b5-efcf-4aa5-90c5-bff1ab0cdbe2')
    def test_create_region_with_specific_id(self):
        # Create a region with a specific id
        r_region_id = data_utils.rand_uuid()
        r_description = data_utils.rand_name('description')
        region = self.client.create_region(
            region_id=r_region_id, description=r_description)['region']
        self.addCleanup(self.client.delete_region, region['id'])
        # Asserting Create Region with specific id response body
        self.assertEqual(r_region_id, region['id'])
        self.assertEqual(r_description, region['description'])

    @decorators.idempotent_id('d180bf99-544a-445c-ad0d-0c0d27663796')
    def test_list_regions(self):
        # Get a list of regions
        fetched_regions = self.client.list_regions()['regions']
        missing_regions =\
            [e for e in self.setup_regions if e not in fetched_regions]
        # Asserting List Regions response
        self.assertEqual(0, len(missing_regions),
                         "Failed to find region %s in fetched list" %
                         ', '.join(str(e) for e in missing_regions))

    @decorators.idempotent_id('2d1057cb-bbde-413a-acdf-e2d265284542')
    def test_list_regions_filter_by_parent_region_id(self):
        # Add a sub-region to one of the existing test regions
        r_description = data_utils.rand_name('description')
        region = self.client.create_region(
            description=r_description,
            parent_region_id=self.setup_regions[0]['id'])['region']
        self.addCleanup(self.client.delete_region, region['id'])
        # Get the list of regions filtering with the parent_region_id
        params = {'parent_region_id': self.setup_regions[0]['id']}
        fetched_regions = self.client.list_regions(params=params)['regions']
        # Asserting list regions response
        self.assertIn(region, fetched_regions)
        for r in fetched_regions:
            self.assertEqual(self.setup_regions[0]['id'],
                             r['parent_region_id'])