Debian Codegraph @

keystoneclient/tests/unit/v3/test_endpoints.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 keystoneclient import exceptions
16 from keystoneclient.tests.unit.v3 import utils
17 from keystoneclient.v3 import endpoints
18
19
20 class EndpointTests(utils.ClientTestCase, utils.CrudTests):
21 def setUp(self):
22 super(EndpointTests, self).setUp()
23 self.key = 'endpoint'
24 self.collection_key = 'endpoints'
25 self.model = endpoints.Endpoint
26 self.manager = self.client.endpoints
27
28 def new_ref(self, **kwargs):
29 kwargs = super(EndpointTests, self).new_ref(**kwargs)
30 kwargs.setdefault('interface', 'public')
31 kwargs.setdefault('region', uuid.uuid4().hex)
32 kwargs.setdefault('service_id', uuid.uuid4().hex)
33 kwargs.setdefault('url', uuid.uuid4().hex)
34 kwargs.setdefault('enabled', True)
35 return kwargs
36
37 def test_create_public_interface(self):
38 ref = self.new_ref(interface='public')
39 self.test_create(ref)
40
41 def test_create_admin_interface(self):
42 ref = self.new_ref(interface='admin')
43 self.test_create(ref)
44
45 def test_create_internal_interface(self):
46 ref = self.new_ref(interface='internal')
47 self.test_create(ref)
48
49 def test_create_invalid_interface(self):
50 ref = self.new_ref(interface=uuid.uuid4().hex)
51 self.assertRaises(exceptions.ValidationError, self.manager.create,
52 **utils.parameterize(ref))
53
54 def test_update_public_interface(self):
55 ref = self.new_ref(interface='public')
56 self.test_update(ref)
57
58 def test_update_admin_interface(self):
59 ref = self.new_ref(interface='admin')
60 self.test_update(ref)
61
62 def test_update_internal_interface(self):
63 ref = self.new_ref(interface='internal')
64 self.test_update(ref)
65
66 def test_update_invalid_interface(self):
67 ref = self.new_ref(interface=uuid.uuid4().hex)
68 ref['endpoint'] = "fake_endpoint"
69 self.assertRaises(exceptions.ValidationError, self.manager.update,
70 **utils.parameterize(ref))
71
72 def test_list_public_interface(self):
73 interface = 'public'
74 expected_path = 'v3/%s?interface=%s' % (self.collection_key, interface)
75 self.test_list(expected_path=expected_path, interface=interface)
76
77 def test_list_admin_interface(self):
78 interface = 'admin'
79 expected_path = 'v3/%s?interface=%s' % (self.collection_key, interface)
80 self.test_list(expected_path=expected_path, interface=interface)
81
82 def test_list_internal_interface(self):
83 interface = 'admin'
84 expected_path = 'v3/%s?interface=%s' % (self.collection_key, interface)
85 self.test_list(expected_path=expected_path, interface=interface)
86
87 def test_list_invalid_interface(self):
88 interface = uuid.uuid4().hex
89 expected_path = 'v3/%s?interface=%s' % (self.collection_key, interface)
90 self.assertRaises(exceptions.ValidationError, self.manager.list,
91 expected_path=expected_path, interface=interface)
92
93 def test_list_filtered_by_region(self):
94 region_id = uuid.uuid4().hex
95 ref_list = [self.new_ref(region=region_id),
96 self.new_ref(region=region_id)]
97 expected_path = 'v3/%s?region_id=%s' % (self.collection_key, region_id)
98 expected_query = {'region_id': region_id}
99
100 # Validate passing either region or region_id result to the API call.
101 self.test_list(ref_list=ref_list, expected_path=expected_path,
102 expected_query=expected_query, region=region_id)
103 self.test_list(ref_list=ref_list, expected_path=expected_path,
104 expected_query=expected_query, region_id=region_id)