Merge "Add name and enabled param in ListDomain parser"

This commit is contained in:
Zuul 2020-12-22 13:30:59 +00:00 committed by Gerrit Code Review
commit 0fd090eff3
3 changed files with 80 additions and 1 deletions

View File

@ -126,9 +126,30 @@ class DeleteDomain(command.Command):
class ListDomain(command.Lister):
_description = _("List domains")
def get_parser(self, prog_name):
parser = super(ListDomain, self).get_parser(prog_name)
parser.add_argument(
'--name',
metavar='<name>',
help=_('The domain name'),
)
parser.add_argument(
'--enabled',
dest='enabled',
action='store_true',
help=_('The domains that are enabled will be returned'),
)
return parser
def take_action(self, parsed_args):
kwargs = {}
if parsed_args.name:
kwargs['name'] = parsed_args.name
if parsed_args.enabled:
kwargs['enabled'] = True
columns = ('ID', 'Name', 'Enabled', 'Description')
data = self.app.client_manager.identity.domains.list()
data = self.app.client_manager.identity.domains.list(**kwargs)
return (columns,
(utils.get_item_properties(
s, columns,

View File

@ -293,6 +293,61 @@ class TestDomainList(TestDomain):
), )
self.assertEqual(datalist, tuple(data))
def test_domain_list_with_option_name(self):
arglist = ['--name',
self.domain.name]
verifylist = [
('name', self.domain.name)
]
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 = {
'name': self.domain.name
}
self.domains_mock.list.assert_called_with(**kwargs)
collist = ('ID', 'Name', 'Enabled', 'Description')
self.assertEqual(collist, columns)
datalist = ((
self.domain.id,
self.domain.name,
True,
self.domain.description,
), )
self.assertEqual(datalist, tuple(data))
def test_domain_list_with_option_enabled(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.domains_mock.list.assert_called_with(**kwargs)
collist = ('ID', 'Name', 'Enabled', 'Description')
self.assertEqual(collist, columns)
datalist = ((
self.domain.id,
self.domain.name,
True,
self.domain.description,
), )
self.assertEqual(datalist, tuple(data))
class TestDomainSet(TestDomain):

View File

@ -0,0 +1,3 @@
---
features:
- Add ``--name`` and ``--domain`` option to ``domain list`` command.