Merge "marker when retrive audit template"
This commit is contained in:
@@ -178,6 +178,16 @@ fake_responses_sorting = {
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_marker = {
|
||||
'/v1/audit_templates/?marker=f8e47706-efcf-49a4-a5c4-af604eb492f2':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audit_templates": [AUDIT_TMPL2, AUDIT_TMPL3]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_filter_by_goal_uuid = {
|
||||
'/v1/audit_templates/?goal=e75ee410-b32b-465f-88b5-4397705f9473':
|
||||
{
|
||||
@@ -389,6 +399,18 @@ class AuditTemplateManagerTest(utils.BaseTestCase):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(3, len(audit_templates))
|
||||
|
||||
def test_audit_templates_list_marker(self):
|
||||
self.api = utils.FakeAPI(fake_responses_marker)
|
||||
self.mgr = watcherclient.v1.audit_template.AuditTemplateManager(
|
||||
self.api)
|
||||
audit_templates = self.mgr.list(marker=AUDIT_TMPL1['uuid'])
|
||||
expect_url = '/v1/audit_templates/?marker=%s' % AUDIT_TMPL1['uuid']
|
||||
expect = [
|
||||
('GET', expect_url, {}, None)
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(2, len(audit_templates))
|
||||
|
||||
def test_audit_templates_show(self):
|
||||
audit_template = self.mgr.get(AUDIT_TMPL1['uuid'])
|
||||
expect = [
|
||||
|
||||
@@ -128,6 +128,24 @@ class AuditTemplateShellTest(base.CommandTestCase):
|
||||
|
||||
self.m_audit_template_mgr.list.assert_called_once_with(detail=False)
|
||||
|
||||
def test_do_audit_template_list_marker(self):
|
||||
audit_template2 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_2)
|
||||
self.m_audit_template_mgr.list.return_value = [audit_template2]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'audittemplate list --marker '
|
||||
'f8e47706-efcf-49a4-a5c4-af604eb492f2')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(audit_template2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_audit_template_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
marker='f8e47706-efcf-49a4-a5c4-af604eb492f2')
|
||||
|
||||
def test_do_audit_template_list_detail(self):
|
||||
audit_template1 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_1)
|
||||
audit_template2 = resource.AuditTemplate(mock.Mock(), AUDIT_TEMPLATE_2)
|
||||
|
||||
@@ -33,7 +33,7 @@ class AuditTemplateManager(base.Manager):
|
||||
return '/v1/audit_templates/%s' % id_ if id_ else '/v1/audit_templates'
|
||||
|
||||
def list(self, name=None, goal=None, strategy=None, limit=None,
|
||||
sort_key=None, sort_dir=None, detail=False):
|
||||
sort_key=None, sort_dir=None, detail=False, marker=None):
|
||||
"""Retrieve a list of audit template.
|
||||
|
||||
:param name: Name of the audit template
|
||||
@@ -54,13 +54,16 @@ class AuditTemplateManager(base.Manager):
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about audit_templates.
|
||||
|
||||
:param marker: Optional, UUID of the last audit template of
|
||||
the previous page.
|
||||
|
||||
:returns: A list of audit templates.
|
||||
|
||||
"""
|
||||
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 name is not None:
|
||||
filters.append('name=%s' % name)
|
||||
if goal is not None:
|
||||
|
||||
@@ -91,6 +91,13 @@ class ListAuditTemplate(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 audit template of the previous page; '
|
||||
'displays list of audit templates after "marker".'))
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
Reference in New Issue
Block a user