diff --git a/watcherclient/tests/unit/v1/test_goal.py b/watcherclient/tests/unit/v1/test_goal.py index 7f4fd3a..65ef26e 100644 --- a/watcherclient/tests/unit/v1/test_goal.py +++ b/watcherclient/tests/unit/v1/test_goal.py @@ -98,6 +98,16 @@ fake_responses_sorting = { }, } +fake_responses_marker = { + '/v1/goals/?marker=fc087747-61be-4aad-8126-b701731ae836': + { + 'GET': ( + {}, + {"goals": [GOAL2]} + ), + }, +} + class GoalManagerTest(testtools.TestCase): @@ -132,6 +142,17 @@ class GoalManagerTest(testtools.TestCase): self.assertEqual(expect, self.api.calls) self.assertThat(goals, matchers.HasLength(1)) + def test_goals_list_marker(self): + self.api = utils.FakeAPI(fake_responses_marker) + self.mgr = watcherclient.v1.goal.GoalManager(self.api) + goals = self.mgr.list(marker=GOAL1['uuid']) + expect = [ + ('GET', '/v1/goals/?marker=fc087747-61be-4aad-8126-b701731ae836', + {}, None), + ] + self.assertEqual(expect, self.api.calls) + self.assertEqual(1, len(goals)) + def test_goals_list_pagination_no_limit(self): self.api = utils.FakeAPI(fake_responses_pagination) self.mgr = watcherclient.v1.goal.GoalManager(self.api) diff --git a/watcherclient/tests/unit/v1/test_goal_shell.py b/watcherclient/tests/unit/v1/test_goal_shell.py index 1e9ffd8..363ee56 100644 --- a/watcherclient/tests/unit/v1/test_goal_shell.py +++ b/watcherclient/tests/unit/v1/test_goal_shell.py @@ -93,6 +93,23 @@ class GoalShellTest(base.CommandTestCase): self.m_goal_mgr.list.assert_called_once_with(detail=False) + def test_do_goal_list_marker(self): + goal2 = resource.Goal(mock.Mock(), GOAL_2) + self.m_goal_mgr.list.return_value = [goal2] + + exit_code, results = self.run_cmd( + 'goal list --marker fc087747-61be-4aad-8126-b701731ae836') + + self.assertEqual(0, exit_code) + self.assertEqual( + [self.resource_as_dict(goal2, self.SHORT_LIST_FIELDS, + self.SHORT_LIST_FIELD_LABELS)], + results) + + self.m_goal_mgr.list.assert_called_once_with( + detail=False, + marker='fc087747-61be-4aad-8126-b701731ae836') + def test_do_goal_list_detail(self): goal1 = resource.Goal(mock.Mock(), GOAL_1) goal2 = resource.Goal(mock.Mock(), GOAL_2) diff --git a/watcherclient/v1/goal.py b/watcherclient/v1/goal.py index 485a464..994812d 100644 --- a/watcherclient/v1/goal.py +++ b/watcherclient/v1/goal.py @@ -29,7 +29,8 @@ class GoalManager(base.Manager): def _path(goal=None): return '/v1/goals/%s' % goal if goal else '/v1/goals' - def list(self, limit=None, sort_key=None, sort_dir=None, detail=False): + def list(self, limit=None, sort_key=None, sort_dir=None, detail=False, + marker=None): """Retrieve a list of goal. :param limit: The maximum number of results to return per @@ -49,13 +50,15 @@ class GoalManager(base.Manager): :param detail: Optional, boolean whether to return detailed information about audits. - :returns: A list of audits. + :param marker: Optional, UUID of the last goal in the previous page. + + :returns: A list of goals. """ 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) path = '' if detail: path += 'detail' diff --git a/watcherclient/v1/goal_shell.py b/watcherclient/v1/goal_shell.py index 351e42d..5852975 100644 --- a/watcherclient/v1/goal_shell.py +++ b/watcherclient/v1/goal_shell.py @@ -96,6 +96,13 @@ class ListGoal(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 goal in the previous page; ' + 'displays list of goals after "marker".')) return parser