Merge "Follow-up to headers handler to fix find_bulk()"

This commit is contained in:
Jenkins 2017-05-04 00:33:38 +00:00 committed by Gerrit Code Review
commit 57b3f937cd
2 changed files with 18 additions and 1 deletions

View File

@ -179,6 +179,8 @@ class BaseAPI(object):
request (GET will be sent by default)
:param bool detailed:
Adds '/details' to path for some APIs to return extended attributes
:param dict headers:
Headers dictionary to pass to requests
:returns:
JSON-decoded response, could be a list or a dict-wrapped-list
"""
@ -284,6 +286,7 @@ class BaseAPI(object):
def find_bulk(
self,
path,
headers=None,
**kwargs
):
"""Bulk load and filter locally
@ -292,9 +295,12 @@ class BaseAPI(object):
The API-specific portion of the URL path
:param kwargs:
A dict of AVPs to match - logical AND
:param dict headers:
Headers dictionary to pass to requests
:returns: list of resource dicts
"""
print("keys: %s" % kwargs.keys())
items = self.list(path)
if isinstance(items, dict):
# strip off the enclosing dict
@ -349,6 +355,8 @@ class BaseAPI(object):
search expression (required, really)
:param string attr:
name of attribute for secondary search
:param dict headers:
Headers dictionary to pass to requests
"""
try:
@ -371,7 +379,10 @@ class BaseAPI(object):
headers=headers,
**kwargs
)
except ksa_exceptions.NotFound:
except (
exceptions.NotFound,
ksa_exceptions.NotFound,
):
msg = _("%s not found") % value
raise exceptions.NotFound(msg)

View File

@ -274,6 +274,9 @@ class TestBaseAPIFind(api_fakes.TestSession):
)
ret = self.api.find_bulk('qaz')
self.assertEqual(api_fakes.LIST_RESP, ret)
# Verify headers arg does not interfere
ret = self.api.find_bulk('qaz', headers={})
self.assertEqual(api_fakes.LIST_RESP, ret)
def test_baseapi_find_bulk_one(self):
self.requests_mock.register_uri(
@ -284,6 +287,9 @@ class TestBaseAPIFind(api_fakes.TestSession):
)
ret = self.api.find_bulk('qaz', id='1')
self.assertEqual([api_fakes.LIST_RESP[0]], ret)
# Verify headers arg does not interfere with search
ret = self.api.find_bulk('qaz', id='1', headers={})
self.assertEqual([api_fakes.LIST_RESP[0]], ret)
ret = self.api.find_bulk('qaz', id='0')
self.assertEqual([], ret)