mirror of https://github.com/docker/docker-py.git
Merge pull request #2476 from feliperuhland/add-search-images-limit
Add limit parameter to image search endpoint
This commit is contained in:
commit
18fdc23b7c
|
|
@ -509,13 +509,14 @@ class ImageApiMixin(object):
|
||||||
res = self._delete(self._url("/images/{0}", image), params=params)
|
res = self._delete(self._url("/images/{0}", image), params=params)
|
||||||
return self._result(res, True)
|
return self._result(res, True)
|
||||||
|
|
||||||
def search(self, term):
|
def search(self, term, limit=None):
|
||||||
"""
|
"""
|
||||||
Search for images on Docker Hub. Similar to the ``docker search``
|
Search for images on Docker Hub. Similar to the ``docker search``
|
||||||
command.
|
command.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
term (str): A term to search for.
|
term (str): A term to search for.
|
||||||
|
limit (int): The maximum number of results to return.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
(list of dicts): The response of the search.
|
(list of dicts): The response of the search.
|
||||||
|
|
@ -524,8 +525,12 @@ class ImageApiMixin(object):
|
||||||
:py:class:`docker.errors.APIError`
|
:py:class:`docker.errors.APIError`
|
||||||
If the server returns an error.
|
If the server returns an error.
|
||||||
"""
|
"""
|
||||||
|
params = {'term': term}
|
||||||
|
if limit is not None:
|
||||||
|
params['limit'] = limit
|
||||||
|
|
||||||
return self._result(
|
return self._result(
|
||||||
self._get(self._url("/images/search"), params={'term': term}),
|
self._get(self._url("/images/search"), params=params),
|
||||||
True
|
True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,11 @@ class ImageCollectionTest(unittest.TestCase):
|
||||||
client.images.search('test')
|
client.images.search('test')
|
||||||
client.api.search.assert_called_with('test')
|
client.api.search.assert_called_with('test')
|
||||||
|
|
||||||
|
def test_search_limit(self):
|
||||||
|
client = make_fake_client()
|
||||||
|
client.images.search('test', limit=5)
|
||||||
|
client.api.search.assert_called_with('test', limit=5)
|
||||||
|
|
||||||
|
|
||||||
class ImageTest(unittest.TestCase):
|
class ImageTest(unittest.TestCase):
|
||||||
def test_short_id(self):
|
def test_short_id(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue