Debian Codegraph @

keystoneclient/tests/unit/v2_0/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.tests.unit.v2_0 import utils
16 from keystoneclient.v2_0 import endpoints
17
18
19 class EndpointTests(utils.ClientTestCase):
20 def setUp(self):
21 super(EndpointTests, self).setUp()
22 self.TEST_ENDPOINTS = {
23 'endpoints': [
24 {
25 'adminurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
26 'id': '8f9531231e044e218824b0e58688d262',
27 'internalurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
28 'publicurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
29 'region': 'RegionOne',
30 },
31 {
32 'adminurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
33 'id': '8f9531231e044e218824b0e58688d263',
34 'internalurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
35 'publicurl': 'http://host-1:8774/v1.1/$(tenant_id)s',
36 'region': 'RegionOne',
37 }
38 ]
39 }
40
41 def test_create_with_optional_params(self):
42 req_body = {
43 "endpoint": {
44 "region": "RegionOne",
45 "publicurl": "http://host-3:8774/v1.1/$(tenant_id)s",
46 "internalurl": "http://host-3:8774/v1.1/$(tenant_id)s",
47 "adminurl": "http://host-3:8774/v1.1/$(tenant_id)s",
48 "service_id": uuid.uuid4().hex,
49 }
50 }
51
52 resp_body = {
53 "endpoint": {
54 "adminurl": "http://host-3:8774/v1.1/$(tenant_id)s",
55 "region": "RegionOne",
56 "id": uuid.uuid4().hex,
57 "internalurl": "http://host-3:8774/v1.1/$(tenant_id)s",
58 "publicurl": "http://host-3:8774/v1.1/$(tenant_id)s",
59 }
60 }
61
62 self.stub_url('POST', ['endpoints'], json=resp_body)
63
64 endpoint = self.client.endpoints.create(
65 region=req_body['endpoint']['region'],
66 publicurl=req_body['endpoint']['publicurl'],
67 adminurl=req_body['endpoint']['adminurl'],
68 internalurl=req_body['endpoint']['internalurl'],
69 service_id=req_body['endpoint']['service_id']
70 )
71 self.assertIsInstance(endpoint, endpoints.Endpoint)
72 self.assertRequestBodyIs(json=req_body)
73
74 def test_create_with_optional_params_as_none(self):
75 req_body_without_defaults = {
76 "endpoint": {
77 "region": "RegionOne",
78 "service_id": uuid.uuid4().hex,
79 "publicurl": "http://host-3:8774/v1.1/$(tenant_id)s",
80 "adminurl": None,
81 "internalurl": None,
82 }
83 }
84
85 resp_body = {
86 "endpoint": {
87 "region": "RegionOne",
88 "id": uuid.uuid4().hex,
89 "publicurl": "http://host-3:8774/v1.1/$(tenant_id)s",
90 "adminurl": None,
91 "internalurl": None,
92 }
93 }
94
95 self.stub_url('POST', ['endpoints'], json=resp_body)
96
97 endpoint_without_defaults = self.client.endpoints.create(
98 region=req_body_without_defaults['endpoint']['region'],
99 publicurl=req_body_without_defaults['endpoint']['publicurl'],
100 service_id=req_body_without_defaults['endpoint']['service_id'],
101 adminurl=None,
102 internalurl=None
103 )
104 self.assertIsInstance(endpoint_without_defaults, endpoints.Endpoint)
105 self.assertRequestBodyIs(json=req_body_without_defaults)
106
107 def test_create_without_optional_params(self):
108 req_body_without_defaults = {
109 "endpoint": {
110 "region": "RegionOne",
111 "service_id": uuid.uuid4().hex,
112 "publicurl": "http://host-3:8774/v1.1/$(tenant_id)s",
113 "adminurl": None,
114 "internalurl": None,
115 }
116 }
117
118 resp_body = {
119 "endpoint": {
120 "region": "RegionOne",
121 "id": uuid.uuid4().hex,
122 "publicurl": "http://host-3:8774/v1.1/$(tenant_id)s",
123 "adminurl": None,
124 "internalurl": None,
125 }
126 }
127
128 self.stub_url('POST', ['endpoints'], json=resp_body)
129
130 endpoint_without_defaults = self.client.endpoints.create(
131 region=req_body_without_defaults['endpoint']['region'],
132 publicurl=req_body_without_defaults['endpoint']['publicurl'],
133 service_id=req_body_without_defaults['endpoint']['service_id']
134 )
135 self.assertIsInstance(endpoint_without_defaults, endpoints.Endpoint)
136 self.assertRequestBodyIs(json=req_body_without_defaults)
137
138 def test_delete(self):
139 self.stub_url('DELETE', ['endpoints', '8f953'], status_code=204)
140 self.client.endpoints.delete('8f953')
141
142 def test_list(self):
143 self.stub_url('GET', ['endpoints'], json=self.TEST_ENDPOINTS)
144
145 endpoint_list = self.client.endpoints.list()
146 [self.assertIsInstance(r, endpoints.Endpoint)
147 for r in endpoint_list]