|
15 | 15 |
|
16 | 16 | import copy |
17 | 17 |
|
| 18 | +from keystoneclient.openstack.common.apiclient import exceptions as ksc_exc |
| 19 | + |
18 | 20 | from openstackclient.identity.v2_0 import project |
19 | 21 | from openstackclient.tests import fakes |
20 | 22 | from openstackclient.tests.identity.v2_0 import fakes as identity_fakes |
@@ -219,6 +221,89 @@ def test_project_create_property(self): |
219 | 221 | ) |
220 | 222 | self.assertEqual(data, datalist) |
221 | 223 |
|
| 224 | + def test_project_create_or_show_exists(self): |
| 225 | + def _raise_conflict(*args, **kwargs): |
| 226 | + raise ksc_exc.Conflict(None) |
| 227 | + |
| 228 | + # need to make this throw an exception... |
| 229 | + self.projects_mock.create.side_effect = _raise_conflict |
| 230 | + |
| 231 | + self.projects_mock.get.return_value = fakes.FakeResource( |
| 232 | + None, |
| 233 | + copy.deepcopy(identity_fakes.PROJECT), |
| 234 | + loaded=True, |
| 235 | + ) |
| 236 | + |
| 237 | + arglist = [ |
| 238 | + '--or-show', |
| 239 | + identity_fakes.project_name, |
| 240 | + ] |
| 241 | + verifylist = [ |
| 242 | + ('name', identity_fakes.project_name), |
| 243 | + ('or_show', True), |
| 244 | + ] |
| 245 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 246 | + |
| 247 | + # DisplayCommandBase.take_action() returns two tuples |
| 248 | + columns, data = self.cmd.take_action(parsed_args) |
| 249 | + |
| 250 | + # ProjectManager.create(name, description, enabled) |
| 251 | + self.projects_mock.get.assert_called_with(identity_fakes.project_name) |
| 252 | + |
| 253 | + # Set expected values |
| 254 | + kwargs = { |
| 255 | + 'description': None, |
| 256 | + 'enabled': True, |
| 257 | + } |
| 258 | + self.projects_mock.create.assert_called_with( |
| 259 | + identity_fakes.project_name, |
| 260 | + **kwargs |
| 261 | + ) |
| 262 | + |
| 263 | + collist = ('description', 'enabled', 'id', 'name') |
| 264 | + self.assertEqual(collist, columns) |
| 265 | + datalist = ( |
| 266 | + identity_fakes.project_description, |
| 267 | + True, |
| 268 | + identity_fakes.project_id, |
| 269 | + identity_fakes.project_name, |
| 270 | + ) |
| 271 | + self.assertEqual(datalist, data) |
| 272 | + |
| 273 | + def test_project_create_or_show_not_exists(self): |
| 274 | + arglist = [ |
| 275 | + '--or-show', |
| 276 | + identity_fakes.project_name, |
| 277 | + ] |
| 278 | + verifylist = [ |
| 279 | + ('name', identity_fakes.project_name), |
| 280 | + ('or_show', True), |
| 281 | + ] |
| 282 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 283 | + |
| 284 | + # DisplayCommandBase.take_action() returns two tuples |
| 285 | + columns, data = self.cmd.take_action(parsed_args) |
| 286 | + |
| 287 | + # Set expected values |
| 288 | + kwargs = { |
| 289 | + 'description': None, |
| 290 | + 'enabled': True, |
| 291 | + } |
| 292 | + self.projects_mock.create.assert_called_with( |
| 293 | + identity_fakes.project_name, |
| 294 | + **kwargs |
| 295 | + ) |
| 296 | + |
| 297 | + collist = ('description', 'enabled', 'id', 'name') |
| 298 | + self.assertEqual(collist, columns) |
| 299 | + datalist = ( |
| 300 | + identity_fakes.project_description, |
| 301 | + True, |
| 302 | + identity_fakes.project_id, |
| 303 | + identity_fakes.project_name, |
| 304 | + ) |
| 305 | + self.assertEqual(datalist, data) |
| 306 | + |
222 | 307 |
|
223 | 308 | class TestProjectDelete(TestProject): |
224 | 309 |
|
|
0 commit comments