Merge "Add id and enabled param in ListIdentityProvider parser"

This commit is contained in:
Zuul 2020-12-01 13:50:56 +00:00 committed by Gerrit Code Review
commit c7a43773c9
3 changed files with 81 additions and 1 deletions

View File

@ -143,10 +143,32 @@ class DeleteIdentityProvider(command.Command):
class ListIdentityProvider(command.Lister):
_description = _("List identity providers")
def get_parser(self, prog_name):
parser = super(ListIdentityProvider, self).get_parser(prog_name)
parser.add_argument(
'--id',
metavar='<id>',
help=_('The Identity Providers ID attribute'),
)
parser.add_argument(
'--enabled',
dest='enabled',
action='store_true',
help=_('The Identity Providers that are enabled will be returned'),
)
return parser
def take_action(self, parsed_args):
columns = ('ID', 'Enabled', 'Domain ID', 'Description')
identity_client = self.app.client_manager.identity
data = identity_client.federation.identity_providers.list()
kwargs = {}
if parsed_args.id:
kwargs['id'] = parsed_args.id
if parsed_args.enabled:
kwargs['enabled'] = True
data = identity_client.federation.identity_providers.list(**kwargs)
return (columns,
(utils.get_item_properties(
s, columns,

View File

@ -384,6 +384,61 @@ class TestIdentityProviderList(TestIdentityProvider):
), )
self.assertListItemEqual(datalist, tuple(data))
def test_identity_provider_list_ID_option(self):
arglist = ['--id',
identity_fakes.idp_id]
verifylist = [
('id', identity_fakes.idp_id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# In base command class Lister in cliff, abstract method take_action()
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
kwargs = {
'id': identity_fakes.idp_id
}
self.identity_providers_mock.list.assert_called_with(**kwargs)
collist = ('ID', 'Enabled', 'Domain ID', 'Description')
self.assertEqual(collist, columns)
datalist = ((
identity_fakes.idp_id,
True,
identity_fakes.domain_id,
identity_fakes.idp_description,
), )
self.assertListItemEqual(datalist, tuple(data))
def test_identity_provider_list_enabled_option(self):
arglist = ['--enabled']
verifylist = [
('enabled', True)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# In base command class Lister in cliff, abstract method take_action()
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
kwargs = {
'enabled': True
}
self.identity_providers_mock.list.assert_called_with(**kwargs)
collist = ('ID', 'Enabled', 'Domain ID', 'Description')
self.assertEqual(collist, columns)
datalist = ((
identity_fakes.idp_id,
True,
identity_fakes.domain_id,
identity_fakes.idp_description,
), )
self.assertListItemEqual(datalist, tuple(data))
class TestIdentityProviderSet(TestIdentityProvider):

View File

@ -0,0 +1,3 @@
---
features:
- Add ``--id`` and ``--enabled`` option to ``identity provider list`` command.