Skip to content

Commit c7a4377

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add id and enabled param in ListIdentityProvider parser"
2 parents 8387b11 + 1e053ba commit c7a4377

3 files changed

Lines changed: 81 additions & 1 deletion

File tree

openstackclient/identity/v3/identity_provider.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,32 @@ def take_action(self, parsed_args):
143143
class ListIdentityProvider(command.Lister):
144144
_description = _("List identity providers")
145145

146+
def get_parser(self, prog_name):
147+
parser = super(ListIdentityProvider, self).get_parser(prog_name)
148+
parser.add_argument(
149+
'--id',
150+
metavar='<id>',
151+
help=_('The Identity Providers’ ID attribute'),
152+
)
153+
parser.add_argument(
154+
'--enabled',
155+
dest='enabled',
156+
action='store_true',
157+
help=_('The Identity Providers that are enabled will be returned'),
158+
)
159+
return parser
160+
146161
def take_action(self, parsed_args):
147162
columns = ('ID', 'Enabled', 'Domain ID', 'Description')
148163
identity_client = self.app.client_manager.identity
149-
data = identity_client.federation.identity_providers.list()
164+
165+
kwargs = {}
166+
if parsed_args.id:
167+
kwargs['id'] = parsed_args.id
168+
if parsed_args.enabled:
169+
kwargs['enabled'] = True
170+
171+
data = identity_client.federation.identity_providers.list(**kwargs)
150172
return (columns,
151173
(utils.get_item_properties(
152174
s, columns,

openstackclient/tests/unit/identity/v3/test_identity_provider.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,61 @@ def test_identity_provider_list_no_options(self):
384384
), )
385385
self.assertListItemEqual(datalist, tuple(data))
386386

387+
def test_identity_provider_list_ID_option(self):
388+
arglist = ['--id',
389+
identity_fakes.idp_id]
390+
verifylist = [
391+
('id', identity_fakes.idp_id)
392+
]
393+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
394+
395+
# In base command class Lister in cliff, abstract method take_action()
396+
# returns a tuple containing the column names and an iterable
397+
# containing the data to be listed.
398+
columns, data = self.cmd.take_action(parsed_args)
399+
400+
kwargs = {
401+
'id': identity_fakes.idp_id
402+
}
403+
self.identity_providers_mock.list.assert_called_with(**kwargs)
404+
405+
collist = ('ID', 'Enabled', 'Domain ID', 'Description')
406+
self.assertEqual(collist, columns)
407+
datalist = ((
408+
identity_fakes.idp_id,
409+
True,
410+
identity_fakes.domain_id,
411+
identity_fakes.idp_description,
412+
), )
413+
self.assertListItemEqual(datalist, tuple(data))
414+
415+
def test_identity_provider_list_enabled_option(self):
416+
arglist = ['--enabled']
417+
verifylist = [
418+
('enabled', True)
419+
]
420+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
421+
422+
# In base command class Lister in cliff, abstract method take_action()
423+
# returns a tuple containing the column names and an iterable
424+
# containing the data to be listed.
425+
columns, data = self.cmd.take_action(parsed_args)
426+
427+
kwargs = {
428+
'enabled': True
429+
}
430+
self.identity_providers_mock.list.assert_called_with(**kwargs)
431+
432+
collist = ('ID', 'Enabled', 'Domain ID', 'Description')
433+
self.assertEqual(collist, columns)
434+
datalist = ((
435+
identity_fakes.idp_id,
436+
True,
437+
identity_fakes.domain_id,
438+
identity_fakes.idp_description,
439+
), )
440+
self.assertListItemEqual(datalist, tuple(data))
441+
387442

388443
class TestIdentityProviderSet(TestIdentityProvider):
389444

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
features:
3+
- Add ``--id`` and ``--enabled`` option to ``identity provider list`` command.

0 commit comments

Comments
 (0)