Added audit_template filter to /audits/detail

In this changeset, I added the 'audit_template' filter to the
/audits/detail endpoint so it has the same set of parameters as
the /audits endpoint.

Change-Id: I2568be18854bd97d4b7879532cb36a7cac532719
This commit is contained in:
Vincent Françoise
2016-06-03 15:05:59 +02:00
parent ca37358cac
commit 8b8d2f01fe
3 changed files with 37 additions and 8 deletions

View File

@@ -63,6 +63,7 @@ import wsme
from wsme import types as wtypes
import wsmeext.pecan as wsme_pecan
from watcher._i18n import _
from watcher.api.controllers import base
from watcher.api.controllers import link
from watcher.api.controllers.v1 import collection

View File

@@ -295,29 +295,30 @@ class AuditsController(rest.RestController):
sort_key=sort_key,
sort_dir=sort_dir)
@wsme_pecan.wsexpose(AuditCollection, types.uuid, int, wtypes.text,
@wsme_pecan.wsexpose(AuditCollection, wtypes.text, types.uuid, int,
wtypes.text, wtypes.text)
def get_all(self, marker=None, limit=None,
sort_key='id', sort_dir='asc', audit_template=None):
def get_all(self, audit_template=None, marker=None, limit=None,
sort_key='id', sort_dir='asc'):
"""Retrieve a list of audits.
:param audit_template: Optional UUID or name of an audit
:param marker: pagination marker for large data sets.
:param limit: maximum number of resources to return in a single result.
:param sort_key: column to sort results by. Default: id.
:param sort_dir: direction to sort. "asc" or "desc". Default: asc.
:param audit_template: Optional UUID or name of an audit
template, to get only audits for that audit template.
"""
return self._get_audits_collection(marker, limit, sort_key,
sort_dir,
audit_template=audit_template)
@wsme_pecan.wsexpose(AuditCollection, types.uuid, int, wtypes.text,
wtypes.text)
def detail(self, marker=None, limit=None,
@wsme_pecan.wsexpose(AuditCollection, wtypes.text, types.uuid, int,
wtypes.text, wtypes.text)
def detail(self, audit_template=None, marker=None, limit=None,
sort_key='id', sort_dir='asc'):
"""Retrieve a list of audits with detail.
:param audit_template: Optional UUID or name of an audit
:param marker: pagination marker for large data sets.
:param limit: maximum number of resources to return in a single result.
:param sort_key: column to sort results by. Default: id.
@@ -332,7 +333,8 @@ class AuditsController(rest.RestController):
resource_url = '/'.join(['audits', 'detail'])
return self._get_audits_collection(marker, limit,
sort_key, sort_dir, expand,
resource_url)
resource_url,
audit_template=audit_template)
@wsme_pecan.wsexpose(Audit, types.uuid)
def get_one(self, audit_uuid):

View File

@@ -241,6 +241,32 @@ class TestListAudit(api_base.FunctionalTest):
self.assertEqual(audit_template_uuid,
audit['audit_template_uuid'])
def test_detail_filter_by_audit_template_uuid(self):
audit_template_uuid = utils.generate_uuid()
audit_template_name = 'My_Audit_Template'
audit_template = obj_utils.create_test_audit_template(
self.context,
uuid=audit_template_uuid,
name=audit_template_name)
number_of_audits_with_audit_template_id = 5
for id_ in range(number_of_audits_with_audit_template_id):
obj_utils.create_test_audit(self.context, id=id_,
uuid=utils.generate_uuid(),
audit_template_id=audit_template.id)
for id_ in range(6, 8):
obj_utils.create_test_audit(self.context, id=id_,
uuid=utils.generate_uuid())
response = self.get_json('/audits/detail?audit_template=%s'
% audit_template_uuid)
audits = response['audits']
self.assertEqual(5, len(audits))
for audit in audits:
self.assertEqual(audit_template_uuid,
audit['audit_template_uuid'])
def test_filter_by_audit_template_name(self):
audit_template_uuid = utils.generate_uuid()
audit_template_name = 'My_Audit_Template'