Debian Codegraph @

keystoneclient/tests/functional/v3/test_regions.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 import uuid
14
15 from keystoneauth1.exceptions import http
16
17 from keystoneclient.tests.functional import base
18 from keystoneclient.tests.functional.v3 import client_fixtures as fixtures
19
20
21 class RegionsTestCase(base.V3ClientTestCase):
22
23 def check_region(self, region, region_ref=None):
24 self.assertIsNotNone(region.id)
25 self.assertIn('self', region.links)
26 self.assertIn('/regions/' + region.id, region.links['self'])
27
28 # There is no guarantee the below attributes are present in region
29 if hasattr(region_ref, 'description'):
30 self.assertEqual(region_ref['description'], region.description)
31 if hasattr(region_ref, 'parent_region'):
32 self.assertEqual(
33 region_ref['parent_region'],
34 region.parent_region)
35
36 def test_create_region(self):
37 region_ref = {'description': uuid.uuid4().hex}
38
39 region = self.client.regions.create(**region_ref)
40 self.addCleanup(self.client.regions.delete, region)
41 self.check_region(region, region_ref)
42
43 def test_get_region(self):
44 region = fixtures.Region(self.client)
45 self.useFixture(region)
46
47 region_ret = self.client.regions.get(region.id)
48 self.check_region(region_ret, region.ref)
49
50 def test_list_regions(self):
51 region_one = fixtures.Region(self.client)
52 self.useFixture(region_one)
53
54 region_two = fixtures.Region(self.client, parent_region=region_one.id)
55 self.useFixture(region_two)
56
57 regions = self.client.regions.list()
58
59 # All regions are valid
60 for region in regions:
61 self.check_region(region)
62
63 self.assertIn(region_one.entity, regions)
64 self.assertIn(region_two.entity, regions)
65
66 def test_update_region(self):
67 parent = fixtures.Region(self.client)
68 self.useFixture(parent)
69
70 region = fixtures.Region(self.client)
71 self.useFixture(region)
72
73 new_description = uuid.uuid4().hex
74 region_ret = self.client.regions.update(region.id,
75 description=new_description,
76 parent_region=parent.id)
77 self.check_region(region_ret, region.ref)
78
79 def test_delete_region(self):
80 region = self.client.regions.create()
81
82 self.client.regions.delete(region.id)
83 self.assertRaises(http.NotFound,
84 self.client.regions.get,
85 region.id)