Add capability to update description of an IdP
Change-Id: I854067642bbfde6fdf84b22b9cc1de8afc7767c0 Closes-Bug: #1515815
This commit is contained in:
		| @@ -81,6 +81,7 @@ Set identity provider properties | ||||
|  | ||||
|     os identity provider set | ||||
|         [--remote-id <remote-id> [...] | --remote-id-file <file-name>] | ||||
|         [--description <description>] | ||||
|         [--enable | --disable] | ||||
|         <identity-provider> | ||||
|  | ||||
| @@ -94,6 +95,10 @@ Set identity provider properties | ||||
|     Name of a file that contains many remote IDs to associate with the identity | ||||
|     provider, one per line | ||||
|  | ||||
| .. option:: --description | ||||
|  | ||||
|     Set identity provider description | ||||
|  | ||||
| .. option:: --enable | ||||
|  | ||||
|     Enable the identity provider | ||||
|   | ||||
| @@ -142,6 +142,11 @@ class SetIdentityProvider(command.Command): | ||||
|             metavar='<identity-provider>', | ||||
|             help='Identity provider to modify', | ||||
|         ) | ||||
|         parser.add_argument( | ||||
|             '--description', | ||||
|             metavar='<description>', | ||||
|             help='Set identity provider description', | ||||
|         ) | ||||
|         identity_remote_id_provider = parser.add_mutually_exclusive_group() | ||||
|         identity_remote_id_provider.add_argument( | ||||
|             '--remote-id', | ||||
| @@ -174,8 +179,10 @@ class SetIdentityProvider(command.Command): | ||||
|         federation_client = self.app.client_manager.identity.federation | ||||
|  | ||||
|         # Basic argument checking | ||||
|         if (not parsed_args.enable and not parsed_args.disable and not | ||||
|                 parsed_args.remote_id and not parsed_args.remote_id_file): | ||||
|         if (not parsed_args.enable and not parsed_args.disable and | ||||
|                 not parsed_args.remote_id and | ||||
|                 not parsed_args.remote_id_file and | ||||
|                 not parsed_args.description): | ||||
|             self.log.error('No changes requested') | ||||
|             return (None, None) | ||||
|  | ||||
| @@ -190,6 +197,8 @@ class SetIdentityProvider(command.Command): | ||||
|  | ||||
|         # Setup keyword args for the client | ||||
|         kwargs = {} | ||||
|         if parsed_args.description: | ||||
|             kwargs['description'] = parsed_args.description | ||||
|         if parsed_args.enable: | ||||
|             kwargs['enabled'] = True | ||||
|         if parsed_args.disable: | ||||
|   | ||||
| @@ -374,6 +374,50 @@ class TestIdentityProviderSet(TestIdentityProvider): | ||||
|         super(TestIdentityProviderSet, self).setUp() | ||||
|         self.cmd = identity_provider.SetIdentityProvider(self.app, None) | ||||
|  | ||||
|     def test_identity_provider_set_description(self): | ||||
|         """Set Identity Provider's description. """ | ||||
|         def prepare(self): | ||||
|             """Prepare fake return objects before the test is executed""" | ||||
|             updated_idp = copy.deepcopy(identity_fakes.IDENTITY_PROVIDER) | ||||
|             updated_idp['enabled'] = False | ||||
|             resources = fakes.FakeResource( | ||||
|                 None, | ||||
|                 updated_idp, | ||||
|                 loaded=True | ||||
|             ) | ||||
|             self.identity_providers_mock.update.return_value = resources | ||||
|  | ||||
|         prepare(self) | ||||
|         new_description = 'new desc' | ||||
|         arglist = [ | ||||
|             '--description', new_description, | ||||
|             identity_fakes.idp_id | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('identity_provider', identity_fakes.idp_id), | ||||
|             ('description', new_description), | ||||
|             ('enable', False), | ||||
|             ('disable', False), | ||||
|             ('remote_id', None) | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         self.identity_providers_mock.update.assert_called_with( | ||||
|             identity_fakes.idp_id, | ||||
|             description=new_description | ||||
|         ) | ||||
|  | ||||
|         collist = ('description', 'enabled', 'id', 'remote_ids') | ||||
|         self.assertEqual(collist, columns) | ||||
|         datalist = ( | ||||
|             identity_fakes.idp_description, | ||||
|             False, | ||||
|             identity_fakes.idp_id, | ||||
|             identity_fakes.idp_remote_ids | ||||
|         ) | ||||
|         self.assertEqual(datalist, data) | ||||
|  | ||||
|     def test_identity_provider_disable(self): | ||||
|         """Disable Identity Provider | ||||
|  | ||||
| @@ -398,6 +442,7 @@ class TestIdentityProviderSet(TestIdentityProvider): | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('identity_provider', identity_fakes.idp_id), | ||||
|             ('description', None), | ||||
|             ('enable', False), | ||||
|             ('disable', True), | ||||
|             ('remote_id', identity_fakes.idp_remote_ids) | ||||
| @@ -443,6 +488,7 @@ class TestIdentityProviderSet(TestIdentityProvider): | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('identity_provider', identity_fakes.idp_id), | ||||
|             ('description', None), | ||||
|             ('enable', True), | ||||
|             ('disable', False), | ||||
|             ('remote_id', identity_fakes.idp_remote_ids) | ||||
| @@ -488,6 +534,7 @@ class TestIdentityProviderSet(TestIdentityProvider): | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('identity_provider', identity_fakes.idp_id), | ||||
|             ('description', None), | ||||
|             ('enable', True), | ||||
|             ('disable', False), | ||||
|             ('remote_id', [self.new_remote_id]) | ||||
| @@ -533,6 +580,7 @@ class TestIdentityProviderSet(TestIdentityProvider): | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('identity_provider', identity_fakes.idp_id), | ||||
|             ('description', None), | ||||
|             ('enable', True), | ||||
|             ('disable', False), | ||||
|             ('remote_id_file', self.new_remote_id), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 lin-hua-cheng
					lin-hua-cheng