Merge "Expose include_rules param in library policy API GET methods"
This commit is contained in:
commit
00e967729f
|
@ -43,6 +43,7 @@ class LibraryPolicyModel(base.APIModel):
|
|||
a list of items in the model. Additional keys set in the
|
||||
dict will also be rendered for the user.
|
||||
"""
|
||||
include_rules = params.get('include_rules', True)
|
||||
try:
|
||||
# Note: name is included as a filtering parameter in get_items
|
||||
# rather than a key in get_item because the API does not commit to
|
||||
|
@ -52,34 +53,37 @@ class LibraryPolicyModel(base.APIModel):
|
|||
try:
|
||||
policy = self.invoke_rpc(
|
||||
base.LIBRARY_SERVICE_ID, 'get_policy_by_name',
|
||||
{'name': params['name'], 'include_rules': True})
|
||||
{'name': params['name'],
|
||||
'include_rules': include_rules})
|
||||
return {"results": [policy]}
|
||||
except KeyError: # not found
|
||||
return {"results": []}
|
||||
else:
|
||||
# Note(thread-safety): blocking call
|
||||
return {"results": self.invoke_rpc(base.LIBRARY_SERVICE_ID,
|
||||
'get_policies',
|
||||
{})}
|
||||
return {"results": self.invoke_rpc(
|
||||
base.LIBRARY_SERVICE_ID,
|
||||
'get_policies', {'include_rules': include_rules})}
|
||||
except exception.CongressException as e:
|
||||
raise webservice.DataModelException.create(e)
|
||||
|
||||
# Note(thread-safety): blocking function
|
||||
def get_item(self, id_, params, context=None):
|
||||
"""Retrieve item with name name from model.
|
||||
"""Retrieve item with id from model.
|
||||
|
||||
:param: name: The unique name of the item to retrieve
|
||||
:param: id_: The id of the item to retrieve
|
||||
:param: params: A dict-like object containing parameters
|
||||
from the request query string and body.
|
||||
:param: context: Key-values providing frame of reference of request
|
||||
|
||||
:returns: The matching item or None if no item named name exists.
|
||||
:returns: The matching item or None if no item with id exists.
|
||||
"""
|
||||
try:
|
||||
# Note(thread-safety): blocking call
|
||||
include_rules = params.get('include_rules', True)
|
||||
return self.invoke_rpc(base.LIBRARY_SERVICE_ID,
|
||||
'get_policy',
|
||||
{'id_': id_, 'include_rules': True})
|
||||
{'id_': id_,
|
||||
'include_rules': include_rules})
|
||||
except exception.CongressException as e:
|
||||
raise webservice.DataModelException.create(e)
|
||||
|
||||
|
|
|
@ -79,6 +79,11 @@ class TestLibraryPolicyModel(base.SqlTestCase):
|
|||
for p in [self.policy,
|
||||
self.policy2]))
|
||||
|
||||
ret = self.library_policy_model.get_items({'include_rules': False})
|
||||
self.assertTrue(all(p in ret['results']
|
||||
for p in [self.policy_metadata,
|
||||
self.policy2_metadata]))
|
||||
|
||||
def test_get_items_by_name(self):
|
||||
ret = self.library_policy_model.get_items(
|
||||
{'name': 'no-such-policy'})
|
||||
|
@ -93,6 +98,11 @@ class TestLibraryPolicyModel(base.SqlTestCase):
|
|||
ret = self.library_policy_model.get_item(self.policy["id"], {})
|
||||
self.assertEqual(expected_ret, ret)
|
||||
|
||||
ret = self.library_policy_model.get_item(self.policy["id"],
|
||||
{'include_rules': False})
|
||||
del expected_ret['rules']
|
||||
self.assertEqual(expected_ret, ret)
|
||||
|
||||
def test_get_invalid_item(self):
|
||||
self.assertRaises(KeyError,
|
||||
self.library_policy_model.get_item,
|
||||
|
|
Loading…
Reference in New Issue