Merge "marker when retrive audit"
This commit is contained in:
@@ -145,6 +145,16 @@ fake_responses_strategy = {
|
||||
},
|
||||
}
|
||||
|
||||
fake_responses_marker = {
|
||||
'/v1/audits/?marker=5869da81-4876-4687-a1ed-12cd64cf53d9':
|
||||
{
|
||||
'GET': (
|
||||
{},
|
||||
{"audits": [AUDIT2]}
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class AuditManagerTest(testtools.TestCase):
|
||||
def setUp(self):
|
||||
@@ -229,6 +239,17 @@ class AuditManagerTest(testtools.TestCase):
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audits))
|
||||
|
||||
def test_audits_list_marker(self):
|
||||
self.api = utils.FakeAPI(fake_responses_marker)
|
||||
self.mgr = watcherclient.v1.audit.AuditManager(self.api)
|
||||
audits = self.mgr.list(marker=AUDIT1['uuid'])
|
||||
expect = [
|
||||
('GET', '/v1/audits/?marker=5869da81-4876-4687-a1ed-12cd64cf53d9',
|
||||
{}, None),
|
||||
]
|
||||
self.assertEqual(expect, self.api.calls)
|
||||
self.assertEqual(1, len(audits))
|
||||
|
||||
def test_audits_show(self):
|
||||
audit = self.mgr.get(AUDIT1['uuid'])
|
||||
expect = [
|
||||
|
||||
@@ -172,6 +172,23 @@ class AuditShellTest(base.CommandTestCase):
|
||||
|
||||
self.m_audit_mgr.list.assert_called_once_with(detail=False)
|
||||
|
||||
def test_do_audit_list_marker(self):
|
||||
audit2 = resource.Audit(mock.Mock(), AUDIT_2)
|
||||
self.m_audit_mgr.list.return_value = [audit2]
|
||||
|
||||
exit_code, results = self.run_cmd(
|
||||
'audit list --marker 5869da81-4876-4687-a1ed-12cd64cf53d9')
|
||||
|
||||
self.assertEqual(0, exit_code)
|
||||
self.assertEqual(
|
||||
[self.resource_as_dict(audit2, self.SHORT_LIST_FIELDS,
|
||||
self.SHORT_LIST_FIELD_LABELS)],
|
||||
results)
|
||||
|
||||
self.m_audit_mgr.list.assert_called_once_with(
|
||||
detail=False,
|
||||
marker='5869da81-4876-4687-a1ed-12cd64cf53d9')
|
||||
|
||||
def test_do_audit_list_detail(self):
|
||||
audit1 = resource.Audit(mock.Mock(), AUDIT_1)
|
||||
audit2 = resource.Audit(mock.Mock(), AUDIT_2)
|
||||
|
||||
@@ -36,7 +36,8 @@ class AuditManager(base.Manager):
|
||||
return '/v1/audits/%s' % id if id else '/v1/audits'
|
||||
|
||||
def list(self, audit_template=None, limit=None, sort_key=None,
|
||||
sort_dir=None, detail=False, goal=None, strategy=None):
|
||||
sort_dir=None, detail=False, goal=None, strategy=None,
|
||||
marker=None):
|
||||
"""Retrieve a list of audit.
|
||||
|
||||
:param audit_template: Name of the audit template
|
||||
@@ -57,13 +58,15 @@ class AuditManager(base.Manager):
|
||||
:param detail: Optional, boolean whether to return detailed information
|
||||
about audits.
|
||||
|
||||
:param marker: Optional, UUID of the last audit 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 audit_template is not None:
|
||||
filters.append('audit_template=%s' % audit_template)
|
||||
if goal is not None:
|
||||
|
||||
@@ -88,6 +88,13 @@ class ListAudit(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 in the previous page; '
|
||||
'displays list of audits after "marker".'))
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
Reference in New Issue
Block a user