|
| 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 | + |
| 14 | +import copy |
| 15 | + |
| 16 | +from openstackclient.identity.v2_0 import endpoint |
| 17 | +from openstackclient.tests import fakes |
| 18 | +from openstackclient.tests.identity.v2_0 import fakes as identity_fakes |
| 19 | + |
| 20 | + |
| 21 | +class TestEndpoint(identity_fakes.TestIdentityv2): |
| 22 | + |
| 23 | + def setUp(self): |
| 24 | + super(TestEndpoint, self).setUp() |
| 25 | + |
| 26 | + # Get a shortcut to the EndpointManager Mock |
| 27 | + self.endpoints_mock = self.app.client_manager.identity.endpoints |
| 28 | + self.endpoints_mock.reset_mock() |
| 29 | + |
| 30 | + # Get a shortcut to the ServiceManager Mock |
| 31 | + self.services_mock = self.app.client_manager.identity.services |
| 32 | + self.services_mock.reset_mock() |
| 33 | + |
| 34 | + |
| 35 | +class TestEndpointCreate(TestEndpoint): |
| 36 | + |
| 37 | + def setUp(self): |
| 38 | + super(TestEndpointCreate, self).setUp() |
| 39 | + |
| 40 | + self.endpoints_mock.create.return_value = fakes.FakeResource( |
| 41 | + None, |
| 42 | + copy.deepcopy(identity_fakes.ENDPOINT), |
| 43 | + loaded=True, |
| 44 | + ) |
| 45 | + |
| 46 | + self.services_mock.get.return_value = fakes.FakeResource( |
| 47 | + None, |
| 48 | + copy.deepcopy(identity_fakes.SERVICE), |
| 49 | + loaded=True, |
| 50 | + ) |
| 51 | + |
| 52 | + # Get the command object to test |
| 53 | + self.cmd = endpoint.CreateEndpoint(self.app, None) |
| 54 | + |
| 55 | + def test_endpoint_create(self): |
| 56 | + arglist = [ |
| 57 | + '--publicurl', identity_fakes.endpoint_publicurl, |
| 58 | + '--internalurl', identity_fakes.endpoint_internalurl, |
| 59 | + '--adminurl', identity_fakes.endpoint_adminurl, |
| 60 | + '--region', identity_fakes.endpoint_region, |
| 61 | + identity_fakes.endpoint_name, |
| 62 | + ] |
| 63 | + verifylist = [ |
| 64 | + ('adminurl', identity_fakes.endpoint_adminurl), |
| 65 | + ('internalurl', identity_fakes.endpoint_internalurl), |
| 66 | + ('publicurl', identity_fakes.endpoint_publicurl), |
| 67 | + ('region', identity_fakes.endpoint_region), |
| 68 | + ('service', identity_fakes.service_name), |
| 69 | + ] |
| 70 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 71 | + |
| 72 | + # DisplayCommandBase.take_action() returns two tuples |
| 73 | + columns, data = self.cmd.take_action(parsed_args) |
| 74 | + |
| 75 | + # EndpointManager.create(region, service_id, publicurl, adminurl, |
| 76 | + # internalurl) |
| 77 | + self.endpoints_mock.create.assert_called_with( |
| 78 | + identity_fakes.endpoint_region, |
| 79 | + identity_fakes.service_id, |
| 80 | + identity_fakes.endpoint_publicurl, |
| 81 | + identity_fakes.endpoint_adminurl, |
| 82 | + identity_fakes.endpoint_internalurl, |
| 83 | + ) |
| 84 | + |
| 85 | + collist = ('adminurl', 'id', 'internalurl', 'publicurl', |
| 86 | + 'region', 'service_id', 'service_name', 'service_type') |
| 87 | + self.assertEqual(columns, collist) |
| 88 | + datalist = ( |
| 89 | + identity_fakes.endpoint_adminurl, |
| 90 | + identity_fakes.endpoint_id, |
| 91 | + identity_fakes.endpoint_internalurl, |
| 92 | + identity_fakes.endpoint_publicurl, |
| 93 | + identity_fakes.endpoint_region, |
| 94 | + identity_fakes.service_id, |
| 95 | + identity_fakes.service_name, |
| 96 | + identity_fakes.service_type, |
| 97 | + ) |
| 98 | + |
| 99 | + self.assertEqual(data, datalist) |
| 100 | + |
| 101 | + |
| 102 | +class TestEndpointDelete(TestEndpoint): |
| 103 | + |
| 104 | + def setUp(self): |
| 105 | + super(TestEndpointDelete, self).setUp() |
| 106 | + |
| 107 | + self.endpoints_mock.get.return_value = fakes.FakeResource( |
| 108 | + None, |
| 109 | + copy.deepcopy(identity_fakes.ENDPOINT), |
| 110 | + loaded=True, |
| 111 | + ) |
| 112 | + |
| 113 | + self.services_mock.get.return_value = fakes.FakeResource( |
| 114 | + None, |
| 115 | + copy.deepcopy(identity_fakes.SERVICE), |
| 116 | + loaded=True, |
| 117 | + ) |
| 118 | + |
| 119 | + self.endpoints_mock.delete.return_value = None |
| 120 | + |
| 121 | + # Get the command object to test |
| 122 | + self.cmd = endpoint.DeleteEndpoint(self.app, None) |
| 123 | + |
| 124 | + def test_endpoint_delete_no_options(self): |
| 125 | + arglist = [ |
| 126 | + identity_fakes.endpoint_id, |
| 127 | + ] |
| 128 | + verifylist = [ |
| 129 | + ('endpoint', identity_fakes.endpoint_id), |
| 130 | + ] |
| 131 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 132 | + |
| 133 | + # DisplayCommandBase.take_action() returns two tuples |
| 134 | + self.cmd.take_action(parsed_args) |
| 135 | + |
| 136 | + self.endpoints_mock.delete.assert_called_with( |
| 137 | + identity_fakes.endpoint_id, |
| 138 | + ) |
| 139 | + |
| 140 | + |
| 141 | +class TestEndpointList(TestEndpoint): |
| 142 | + |
| 143 | + def setUp(self): |
| 144 | + super(TestEndpointList, self).setUp() |
| 145 | + |
| 146 | + self.endpoints_mock.list.return_value = [ |
| 147 | + fakes.FakeResource( |
| 148 | + None, |
| 149 | + copy.deepcopy(identity_fakes.ENDPOINT), |
| 150 | + loaded=True, |
| 151 | + ), |
| 152 | + ] |
| 153 | + |
| 154 | + self.services_mock.get.return_value = fakes.FakeResource( |
| 155 | + None, |
| 156 | + copy.deepcopy(identity_fakes.SERVICE), |
| 157 | + loaded=True, |
| 158 | + ) |
| 159 | + |
| 160 | + # Get the command object to test |
| 161 | + self.cmd = endpoint.ListEndpoint(self.app, None) |
| 162 | + |
| 163 | + def test_endpoint_list_no_options(self): |
| 164 | + arglist = [] |
| 165 | + verifylist = [] |
| 166 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 167 | + |
| 168 | + # DisplayCommandBase.take_action() returns two tuples |
| 169 | + columns, data = self.cmd.take_action(parsed_args) |
| 170 | + |
| 171 | + self.endpoints_mock.list.assert_called_with() |
| 172 | + |
| 173 | + collist = ('ID', 'Region', 'Service Name', 'Service Type') |
| 174 | + self.assertEqual(columns, collist) |
| 175 | + datalist = (( |
| 176 | + identity_fakes.endpoint_id, |
| 177 | + identity_fakes.endpoint_region, |
| 178 | + identity_fakes.service_name, |
| 179 | + identity_fakes.service_type, |
| 180 | + ), ) |
| 181 | + self.assertEqual(tuple(data), datalist) |
| 182 | + |
| 183 | + def test_endpoint_list_long(self): |
| 184 | + arglist = [ |
| 185 | + '--long', |
| 186 | + ] |
| 187 | + verifylist = [ |
| 188 | + ('long', True), |
| 189 | + ] |
| 190 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 191 | + |
| 192 | + # DisplayCommandBase.take_action() returns two tuples |
| 193 | + columns, data = self.cmd.take_action(parsed_args) |
| 194 | + |
| 195 | + self.endpoints_mock.list.assert_called_with() |
| 196 | + |
| 197 | + collist = ('ID', 'Region', 'Service Name', 'Service Type', |
| 198 | + 'PublicURL', 'AdminURL', 'InternalURL') |
| 199 | + self.assertEqual(columns, collist) |
| 200 | + datalist = (( |
| 201 | + identity_fakes.endpoint_id, |
| 202 | + identity_fakes.endpoint_region, |
| 203 | + identity_fakes.service_name, |
| 204 | + identity_fakes.service_type, |
| 205 | + identity_fakes.endpoint_publicurl, |
| 206 | + identity_fakes.endpoint_adminurl, |
| 207 | + identity_fakes.endpoint_internalurl, |
| 208 | + ), ) |
| 209 | + self.assertEqual(tuple(data), datalist) |
| 210 | + |
| 211 | + |
| 212 | +class TestEndpointShow(TestEndpoint): |
| 213 | + |
| 214 | + def setUp(self): |
| 215 | + super(TestEndpointShow, self).setUp() |
| 216 | + |
| 217 | + self.endpoints_mock.list.return_value = [ |
| 218 | + fakes.FakeResource( |
| 219 | + None, |
| 220 | + copy.deepcopy(identity_fakes.ENDPOINT), |
| 221 | + loaded=True, |
| 222 | + ), |
| 223 | + ] |
| 224 | + |
| 225 | + self.services_mock.get.return_value = fakes.FakeResource( |
| 226 | + None, |
| 227 | + copy.deepcopy(identity_fakes.SERVICE), |
| 228 | + loaded=True, |
| 229 | + ) |
| 230 | + |
| 231 | + # Get the command object to test |
| 232 | + self.cmd = endpoint.ShowEndpoint(self.app, None) |
| 233 | + |
| 234 | + def test_endpoint_show(self): |
| 235 | + arglist = [ |
| 236 | + identity_fakes.endpoint_name, |
| 237 | + ] |
| 238 | + verifylist = [ |
| 239 | + ('endpoint_or_service', identity_fakes.endpoint_name), |
| 240 | + ] |
| 241 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 242 | + |
| 243 | + # DisplayCommandBase.take_action() returns two tuples |
| 244 | + columns, data = self.cmd.take_action(parsed_args) |
| 245 | + |
| 246 | + # EndpointManager.list() |
| 247 | + self.endpoints_mock.list.assert_called_with() |
| 248 | + # ServiceManager.get(name) |
| 249 | + self.services_mock.get.assert_called_with( |
| 250 | + identity_fakes.service_name, |
| 251 | + ) |
| 252 | + |
| 253 | + collist = ('adminurl', 'id', 'internalurl', 'publicurl', |
| 254 | + 'region', 'service_id', 'service_name', 'service_type') |
| 255 | + self.assertEqual(columns, collist) |
| 256 | + datalist = ( |
| 257 | + identity_fakes.endpoint_adminurl, |
| 258 | + identity_fakes.endpoint_id, |
| 259 | + identity_fakes.endpoint_internalurl, |
| 260 | + identity_fakes.endpoint_publicurl, |
| 261 | + identity_fakes.endpoint_region, |
| 262 | + identity_fakes.service_id, |
| 263 | + identity_fakes.service_name, |
| 264 | + identity_fakes.service_type, |
| 265 | + ) |
| 266 | + self.assertEqual(data, datalist) |
0 commit comments