Merge "Add marker option for strategy in watcher-client"
This commit is contained in:
commit
76a01b0c7c
watcherclient
@ -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):
|
class StrategyManagerTest(testtools.TestCase):
|
||||||
|
|
||||||
@ -131,6 +141,19 @@ class StrategyManagerTest(testtools.TestCase):
|
|||||||
self.assertEqual(expect, self.api.calls)
|
self.assertEqual(expect, self.api.calls)
|
||||||
self.assertEqual(1, len(strategies))
|
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):
|
def test_strategies_list_limit(self):
|
||||||
self.api = utils.FakeAPI(fake_responses_pagination)
|
self.api = utils.FakeAPI(fake_responses_pagination)
|
||||||
self.mgr = watcherclient.v1.strategy.StrategyManager(self.api)
|
self.mgr = watcherclient.v1.strategy.StrategyManager(self.api)
|
||||||
|
@ -90,6 +90,23 @@ class StrategyShellTest(base.CommandTestCase):
|
|||||||
|
|
||||||
self.m_strategy_mgr.list.assert_called_once_with(detail=False)
|
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):
|
def test_do_strategy_list_detail(self):
|
||||||
strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
|
strategy1 = resource.Strategy(mock.Mock(), STRATEGY_1)
|
||||||
strategy2 = resource.Strategy(mock.Mock(), STRATEGY_2)
|
strategy2 = resource.Strategy(mock.Mock(), STRATEGY_2)
|
||||||
|
@ -38,7 +38,7 @@ class StrategyManager(base.Manager):
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
def list(self, goal=None, limit=None, sort_key=None,
|
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.
|
"""Retrieve a list of strategy.
|
||||||
|
|
||||||
:param goal: The UUID of the goal to filter by
|
: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
|
:param detail: Optional, boolean whether to return detailed information
|
||||||
about audits.
|
about audits.
|
||||||
|
:param marker: Optional, UUID of the last strategy in the previous
|
||||||
|
page.
|
||||||
:returns: A list of audits.
|
:returns: A list of audits.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
limit = int(limit)
|
limit = int(limit)
|
||||||
|
|
||||||
filters = utils.common_filters(limit, sort_key, sort_dir)
|
filters = utils.common_filters(limit, sort_key, sort_dir, marker)
|
||||||
|
|
||||||
if goal:
|
if goal:
|
||||||
filters.append(parse.urlencode(dict(goal=goal)))
|
filters.append(parse.urlencode(dict(goal=goal)))
|
||||||
|
@ -123,7 +123,13 @@ class ListStrategy(command.Lister):
|
|||||||
metavar='<direction>',
|
metavar='<direction>',
|
||||||
choices=['asc', 'desc'],
|
choices=['asc', 'desc'],
|
||||||
help='Sort direction: "asc" (the default) or "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
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user