diff --git a/watcherclient/tests/unit/v1/test_strategy.py b/watcherclient/tests/unit/v1/test_strategy.py index d6f332e..59cd90d 100644 --- a/watcherclient/tests/unit/v1/test_strategy.py +++ b/watcherclient/tests/unit/v1/test_strategy.py @@ -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) diff --git a/watcherclient/tests/unit/v1/test_strategy_shell.py b/watcherclient/tests/unit/v1/test_strategy_shell.py index 2834fe1..7a15687 100644 --- a/watcherclient/tests/unit/v1/test_strategy_shell.py +++ b/watcherclient/tests/unit/v1/test_strategy_shell.py @@ -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) diff --git a/watcherclient/v1/strategy.py b/watcherclient/v1/strategy.py index c464513..0d91b07 100644 --- a/watcherclient/v1/strategy.py +++ b/watcherclient/v1/strategy.py @@ -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))) diff --git a/watcherclient/v1/strategy_shell.py b/watcherclient/v1/strategy_shell.py index 7c0161b..88fd1d8 100644 --- a/watcherclient/v1/strategy_shell.py +++ b/watcherclient/v1/strategy_shell.py @@ -123,7 +123,13 @@ class ListStrategy(command.Lister): metavar='', choices=['asc', 'desc'], help='Sort direction: "asc" (the default) or "desc".') - + parser.add_argument( + '--marker', + dest='marker', + metavar='', + 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):