|
15 | 15 | import copy |
16 | 16 | from unittest import mock |
17 | 17 |
|
| 18 | +from osc_lib import exceptions |
| 19 | + |
18 | 20 | from openstackclient.identity.v3 import identity_provider |
19 | 21 | from openstackclient.tests.unit import fakes |
20 | 22 | from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes |
| 23 | +from openstackclient.tests.unit import utils as test_utils |
21 | 24 |
|
22 | 25 |
|
23 | 26 | class TestIdentityProvider(identity_fakes.TestFederatedIdentity): |
@@ -308,6 +311,86 @@ def test_create_identity_provider_domain_id(self): |
308 | 311 | self.assertEqual(self.columns, columns) |
309 | 312 | self.assertCountEqual(self.datalist, data) |
310 | 313 |
|
| 314 | + def test_create_identity_provider_authttl_positive(self): |
| 315 | + arglist = [ |
| 316 | + '--authorization-ttl', '60', |
| 317 | + identity_fakes.idp_id, |
| 318 | + ] |
| 319 | + verifylist = [ |
| 320 | + ('identity_provider_id', identity_fakes.idp_id), |
| 321 | + ('authorization_ttl', 60), |
| 322 | + ] |
| 323 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 324 | + columns, data = self.cmd.take_action(parsed_args) |
| 325 | + |
| 326 | + # Set expected values |
| 327 | + kwargs = { |
| 328 | + 'remote_ids': None, |
| 329 | + 'description': None, |
| 330 | + 'domain_id': None, |
| 331 | + 'enabled': True, |
| 332 | + 'authorization_ttl': 60, |
| 333 | + } |
| 334 | + |
| 335 | + self.identity_providers_mock.create.assert_called_with( |
| 336 | + id=identity_fakes.idp_id, |
| 337 | + **kwargs |
| 338 | + ) |
| 339 | + |
| 340 | + self.assertEqual(self.columns, columns) |
| 341 | + self.assertCountEqual(self.datalist, data) |
| 342 | + |
| 343 | + def test_create_identity_provider_authttl_zero(self): |
| 344 | + arglist = [ |
| 345 | + '--authorization-ttl', '0', |
| 346 | + identity_fakes.idp_id, |
| 347 | + ] |
| 348 | + verifylist = [ |
| 349 | + ('identity_provider_id', identity_fakes.idp_id), |
| 350 | + ('authorization_ttl', 0), |
| 351 | + ] |
| 352 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 353 | + columns, data = self.cmd.take_action(parsed_args) |
| 354 | + |
| 355 | + # Set expected values |
| 356 | + kwargs = { |
| 357 | + 'remote_ids': None, |
| 358 | + 'description': None, |
| 359 | + 'domain_id': None, |
| 360 | + 'enabled': True, |
| 361 | + 'authorization_ttl': 0, |
| 362 | + } |
| 363 | + |
| 364 | + self.identity_providers_mock.create.assert_called_with( |
| 365 | + id=identity_fakes.idp_id, |
| 366 | + **kwargs |
| 367 | + ) |
| 368 | + |
| 369 | + self.assertEqual(self.columns, columns) |
| 370 | + self.assertCountEqual(self.datalist, data) |
| 371 | + |
| 372 | + def test_create_identity_provider_authttl_negative(self): |
| 373 | + arglist = [ |
| 374 | + '--authorization-ttl', '-60', |
| 375 | + identity_fakes.idp_id, |
| 376 | + ] |
| 377 | + verifylist = [ |
| 378 | + ('identity_provider_id', identity_fakes.idp_id), |
| 379 | + ('authorization_ttl', -60), |
| 380 | + ] |
| 381 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 382 | + self.assertRaises(exceptions.CommandError, self.cmd.take_action, |
| 383 | + parsed_args) |
| 384 | + |
| 385 | + def test_create_identity_provider_authttl_not_int(self): |
| 386 | + arglist = [ |
| 387 | + '--authorization-ttl', 'spam', |
| 388 | + identity_fakes.idp_id, |
| 389 | + ] |
| 390 | + verifylist = [] |
| 391 | + self.assertRaises(test_utils.ParserException, self.check_parser, |
| 392 | + self.cmd, arglist, verifylist) |
| 393 | + |
311 | 394 |
|
312 | 395 | class TestIdentityProviderDelete(TestIdentityProvider): |
313 | 396 |
|
@@ -678,6 +761,93 @@ def prepare(self): |
678 | 761 |
|
679 | 762 | self.cmd.take_action(parsed_args) |
680 | 763 |
|
| 764 | + def test_identity_provider_set_authttl_positive(self): |
| 765 | + def prepare(self): |
| 766 | + """Prepare fake return objects before the test is executed""" |
| 767 | + updated_idp = copy.deepcopy(identity_fakes.IDENTITY_PROVIDER) |
| 768 | + updated_idp['authorization_ttl'] = 60 |
| 769 | + resources = fakes.FakeResource( |
| 770 | + None, |
| 771 | + updated_idp, |
| 772 | + loaded=True |
| 773 | + ) |
| 774 | + self.identity_providers_mock.update.return_value = resources |
| 775 | + |
| 776 | + prepare(self) |
| 777 | + arglist = [ |
| 778 | + '--authorization-ttl', '60', |
| 779 | + identity_fakes.idp_id |
| 780 | + ] |
| 781 | + verifylist = [ |
| 782 | + ('identity_provider', identity_fakes.idp_id), |
| 783 | + ('enable', False), |
| 784 | + ('disable', False), |
| 785 | + ('remote_id', None), |
| 786 | + ('authorization_ttl', 60), |
| 787 | + ] |
| 788 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 789 | + self.cmd.take_action(parsed_args) |
| 790 | + self.identity_providers_mock.update.assert_called_with( |
| 791 | + identity_fakes.idp_id, |
| 792 | + authorization_ttl=60, |
| 793 | + ) |
| 794 | + |
| 795 | + def test_identity_provider_set_authttl_zero(self): |
| 796 | + def prepare(self): |
| 797 | + """Prepare fake return objects before the test is executed""" |
| 798 | + updated_idp = copy.deepcopy(identity_fakes.IDENTITY_PROVIDER) |
| 799 | + updated_idp['authorization_ttl'] = 0 |
| 800 | + resources = fakes.FakeResource( |
| 801 | + None, |
| 802 | + updated_idp, |
| 803 | + loaded=True |
| 804 | + ) |
| 805 | + self.identity_providers_mock.update.return_value = resources |
| 806 | + |
| 807 | + prepare(self) |
| 808 | + arglist = [ |
| 809 | + '--authorization-ttl', '0', |
| 810 | + identity_fakes.idp_id |
| 811 | + ] |
| 812 | + verifylist = [ |
| 813 | + ('identity_provider', identity_fakes.idp_id), |
| 814 | + ('enable', False), |
| 815 | + ('disable', False), |
| 816 | + ('remote_id', None), |
| 817 | + ('authorization_ttl', 0), |
| 818 | + ] |
| 819 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 820 | + self.cmd.take_action(parsed_args) |
| 821 | + self.identity_providers_mock.update.assert_called_with( |
| 822 | + identity_fakes.idp_id, |
| 823 | + authorization_ttl=0, |
| 824 | + ) |
| 825 | + |
| 826 | + def test_identity_provider_set_authttl_negative(self): |
| 827 | + arglist = [ |
| 828 | + '--authorization-ttl', '-1', |
| 829 | + identity_fakes.idp_id |
| 830 | + ] |
| 831 | + verifylist = [ |
| 832 | + ('identity_provider', identity_fakes.idp_id), |
| 833 | + ('enable', False), |
| 834 | + ('disable', False), |
| 835 | + ('remote_id', None), |
| 836 | + ('authorization_ttl', -1), |
| 837 | + ] |
| 838 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 839 | + self.assertRaises(exceptions.CommandError, self.cmd.take_action, |
| 840 | + parsed_args) |
| 841 | + |
| 842 | + def test_identity_provider_set_authttl_not_int(self): |
| 843 | + arglist = [ |
| 844 | + '--authorization-ttl', 'spam', |
| 845 | + identity_fakes.idp_id |
| 846 | + ] |
| 847 | + verifylist = [] |
| 848 | + self.assertRaises(test_utils.ParserException, self.check_parser, |
| 849 | + self.cmd, arglist, verifylist) |
| 850 | + |
681 | 851 |
|
682 | 852 | class TestIdentityProviderShow(TestIdentityProvider): |
683 | 853 |
|
|
0 commit comments