Merge "Add marker option for strategy in watcher-client"

This commit is contained in:
Zuul 2019-03-22 02:05:44 +00:00 committed by Gerrit Code Review
commit 76a01b0c7c
4 changed files with 51 additions and 4 deletions

View File

@ -107,6 +107,16 @@ fake_responses_sorting = {
},
}
fake_responses_marker = {
'/v1/strategies/?marker=2cf86250-d309-4b81-818e-1537f3dba6e5':
{
'GET': (
{},
{"strategies": [STRATEGY2]}
),
},
}
class StrategyManagerTest(testtools.TestCase):
@ -131,6 +141,19 @@ class StrategyManagerTest(testtools.TestCase):
self.assertEqual(expect, self.api.calls)
self.assertEqual(1, len(strategies))
def test_strategies_list_marker(self):
self.api = utils.FakeAPI(fake_responses_marker)
self.mgr = watcherclient.v1.strategy.StrategyManager(self.api)
strategies = self.mgr.list(marker=STRATEGY1['uuid'])
expect = [
('GET',
'/v1/strategies/?marker=2cf86250-d309-4b81-818e-1537f3dba6e5',
{},
None),
]
self.assertEqual(expect, self.api.calls)
self.assertEqual(1, len(strategies))
def test_strategies_list_limit(self):
self.api = utils.FakeAPI(fake_responses_pagination)
self.mgr = watcherclient.v1.strategy.StrategyManager(self.api)

View File

@ -90,6 +90,23 @@ class StrategyShellTest(base.CommandTestCase):
self.m_strategy_mgr.list.assert_called_once_with(detail=False)
def test_do_strategy_list_marker(self):
strategy2 = resource.Strategy(mock.Mock(), STRATEGY_2)
self.m_strategy_mgr.list.return_value = [strategy2]
exit_code, results = self.run_cmd(
'strategy list --marker 2cf86250-d309-4b81-818e-1537f3dba6e5')
self.assertEqual(0, exit_code)
self.assertEqual(
[self.resource_as_dict(strategy2, self.SHORT_LIST_FIELDS,
self.SHORT_LIST_FIELD_LABELS)],
results)
self.m_strategy_mgr.list.assert_called_once_with(
detail=False,
marker='2cf86250-d309-4b81-818e-1537f3dba6e5')
def test_do_strategy_list_detail(self):
strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
strategy2 = resource.Strategy(mock.Mock(), STRATEGY_2)

View File

@ -38,7 +38,7 @@ class StrategyManager(base.Manager):
return path
def list(self, goal=None, limit=None, sort_key=None,
sort_dir=None, detail=False):
sort_dir=None, detail=False, marker=None):
"""Retrieve a list of strategy.
:param goal: The UUID of the goal to filter by
@ -58,14 +58,15 @@ class StrategyManager(base.Manager):
:param detail: Optional, boolean whether to return detailed information
about audits.
:param marker: Optional, UUID of the last strategy in the previous
page.
:returns: A list of audits.
"""
if limit is not None:
limit = int(limit)
filters = utils.common_filters(limit, sort_key, sort_dir)
filters = utils.common_filters(limit, sort_key, sort_dir, marker)
if goal:
filters.append(parse.urlencode(dict(goal=goal)))

View File

@ -123,7 +123,13 @@ class ListStrategy(command.Lister):
metavar='<direction>',
choices=['asc', 'desc'],
help='Sort direction: "asc" (the default) or "desc".')
parser.add_argument(
'--marker',
dest='marker',
metavar='<marker>',
default=None,
help=_('UUID of the last strategy in the previous page; '
'displays list of strategies after "marker".'))
return parser
def take_action(self, parsed_args):