|
16 | 16 | import copy |
17 | 17 | import mock |
18 | 18 |
|
| 19 | +from keystoneclient.openstack.common.apiclient import exceptions as ksc_exc |
19 | 20 | from openstackclient.identity.v2_0 import user |
20 | 21 | from openstackclient.tests import fakes |
21 | 22 | from openstackclient.tests.identity.v2_0 import fakes as identity_fakes |
@@ -342,6 +343,84 @@ def test_user_create_disable(self): |
342 | 343 | ) |
343 | 344 | self.assertEqual(data, datalist) |
344 | 345 |
|
| 346 | + def test_user_create_or_show_exists(self): |
| 347 | + def _raise_conflict(*args, **kwargs): |
| 348 | + raise ksc_exc.Conflict(None) |
| 349 | + |
| 350 | + # need to make this throw an exception... |
| 351 | + self.users_mock.create.side_effect = _raise_conflict |
| 352 | + |
| 353 | + self.users_mock.get.return_value = fakes.FakeResource( |
| 354 | + None, |
| 355 | + copy.deepcopy(identity_fakes.USER), |
| 356 | + loaded=True, |
| 357 | + ) |
| 358 | + |
| 359 | + arglist = [ |
| 360 | + '--or-show', |
| 361 | + identity_fakes.user_name, |
| 362 | + ] |
| 363 | + verifylist = [ |
| 364 | + ('name', identity_fakes.user_name), |
| 365 | + ('or_show', True), |
| 366 | + ] |
| 367 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 368 | + |
| 369 | + # DisplayCommandBase.take_action() returns two tuples |
| 370 | + columns, data = self.cmd.take_action(parsed_args) |
| 371 | + |
| 372 | + # UserManager.create(name, password, email, tenant_id=, enabled=) |
| 373 | + self.users_mock.get.assert_called_with(identity_fakes.user_name) |
| 374 | + |
| 375 | + collist = ('email', 'enabled', 'id', 'name', 'project_id') |
| 376 | + self.assertEqual(collist, columns) |
| 377 | + datalist = ( |
| 378 | + identity_fakes.user_email, |
| 379 | + True, |
| 380 | + identity_fakes.user_id, |
| 381 | + identity_fakes.user_name, |
| 382 | + identity_fakes.project_id, |
| 383 | + ) |
| 384 | + self.assertEqual(datalist, data) |
| 385 | + |
| 386 | + def test_user_create_or_show_not_exists(self): |
| 387 | + arglist = [ |
| 388 | + '--or-show', |
| 389 | + identity_fakes.user_name, |
| 390 | + ] |
| 391 | + verifylist = [ |
| 392 | + ('name', identity_fakes.user_name), |
| 393 | + ('or_show', True), |
| 394 | + ] |
| 395 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 396 | + |
| 397 | + # DisplayCommandBase.take_action() returns two tuples |
| 398 | + columns, data = self.cmd.take_action(parsed_args) |
| 399 | + |
| 400 | + # Set expected values |
| 401 | + kwargs = { |
| 402 | + 'enabled': True, |
| 403 | + 'tenant_id': None, |
| 404 | + } |
| 405 | + # UserManager.create(name, password, email, tenant_id=, enabled=) |
| 406 | + self.users_mock.create.assert_called_with( |
| 407 | + identity_fakes.user_name, |
| 408 | + None, |
| 409 | + None, |
| 410 | + **kwargs |
| 411 | + ) |
| 412 | + |
| 413 | + collist = ('email', 'enabled', 'id', 'name', 'project_id') |
| 414 | + self.assertEqual(collist, columns) |
| 415 | + datalist = ( |
| 416 | + identity_fakes.user_email, |
| 417 | + True, |
| 418 | + identity_fakes.user_id, |
| 419 | + identity_fakes.user_name, |
| 420 | + identity_fakes.project_id, |
| 421 | + ) |
| 422 | + self.assertEqual(datalist, data) |
| 423 | + |
345 | 424 |
|
346 | 425 | class TestUserDelete(TestUser): |
347 | 426 |
|
|
0 commit comments