Merge pull request #2476 from feliperuhland/add-search-images-limit

Add limit parameter to image search endpoint
This commit is contained in:
Anca Iordache 2021-04-06 14:43:07 +01:00 committed by GitHub
commit 18fdc23b7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -509,13 +509,14 @@ class ImageApiMixin(object):
res = self._delete(self._url("/images/{0}", image), params=params)
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``
command.
Args:
term (str): A term to search for.
limit (int): The maximum number of results to return.
Returns:
(list of dicts): The response of the search.
@ -524,8 +525,12 @@ class ImageApiMixin(object):
:py:class:`docker.errors.APIError`
If the server returns an error.
"""
params = {'term': term}
if limit is not None:
params['limit'] = limit
return self._result(
self._get(self._url("/images/search"), params={'term': term}),
self._get(self._url("/images/search"), params=params),
True
)

View File

@ -112,6 +112,11 @@ class ImageCollectionTest(unittest.TestCase):
client.images.search('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):
def test_short_id(self):