Merge "marker when retrive action"
This commit is contained in:
@@ -144,6 +144,16 @@ fake_responses_sorting = {
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_marker = {
|
||||
'/v1/actions/?marker=770ef053-ecb3-48b0-85b5-d55a2dbc6588':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"actions": [ACTION2, ACTION3]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class ActionManagerTest(testtools.TestCase):
|
||||
|
||||
@@ -231,6 +241,20 @@ class ActionManagerTest(testtools.TestCase):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(3, len(actions))
|
||||
|
||||
def test_actions_list_marker(self):
|
||||
self.api = utils.FakeAPI(fake_responses_marker)
|
||||
self.mgr = watcherclient.v1.action.ActionManager(self.api)
|
||||
actions = self.mgr.list(
|
||||
marker='770ef053-ecb3-48b0-85b5-d55a2dbc6588')
|
||||
expect = [
|
||||
('GET',
|
||||
'/v1/actions/?marker=770ef053-ecb3-48b0-85b5-d55a2dbc6588',
|
||||
{},
|
||||
None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(actions))
|
||||
|
||||
def test_actions_show(self):
|
||||
action = self.mgr.get(ACTION1['uuid'])
|
||||
expect = [
|
||||
|
||||
21
watcherclient/tests/unit/v1/test_action_shell.py
Executable file → Normal file
21
watcherclient/tests/unit/v1/test_action_shell.py
Executable file → Normal file
@@ -132,6 +132,27 @@ class ActionShellTest(base.CommandTestCase):
|
||||
|
||||
self.m_action_mgr.list.assert_called_once_with(detail=True)
|
||||
|
||||
def test_do_action_list_marker(self):
|
||||
action2 = resource.Action(mock.Mock(), ACTION_2)
|
||||
action3 = resource.Action(mock.Mock(), ACTION_3)
|
||||
self.m_action_mgr.list.return_value = [
|
||||
action2, action3]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'action list --marker 770ef053-ecb3-48b0-85b5-d55a2dbc6588')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(action2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS),
|
||||
self.resource_as_dict(action3, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_action_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
marker='770ef053-ecb3-48b0-85b5-d55a2dbc6588')
|
||||
|
||||
def test_do_action_show_by_uuid(self):
|
||||
action = resource.Action(mock.Mock(), ACTION_1)
|
||||
self.m_action_mgr.get.return_value = action
|
||||
|
||||
@@ -30,7 +30,7 @@ class ActionManager(base.Manager):
|
||||
return '/v1/actions/%s' % id if id else '/v1/actions'
|
||||
|
||||
def list(self, action_plan=None, audit=None, limit=None, sort_key=None,
|
||||
sort_dir=None, detail=False):
|
||||
sort_dir=None, detail=False, marker=None):
|
||||
"""Retrieve a list of action.
|
||||
|
||||
:param action_plan: UUID of the action plan
|
||||
@@ -52,13 +52,15 @@ class ActionManager(base.Manager):
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about actions.
|
||||
|
||||
:param marker: Optional, UUID of the last action in the previous page.
|
||||
|
||||
:returns: A list of actions.
|
||||
|
||||
"""
|
||||
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 action_plan is not None:
|
||||
filters.append('action_plan_uuid=%s' % action_plan)
|
||||
if audit is not None:
|
||||
|
||||
@@ -83,6 +83,13 @@ class ListAction(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 action in the previous page; '
|
||||
'displays list of actions after "marker".'))
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
Reference in New Issue
Block a user