Skip to content

Commit

Permalink
Add limit parameter to image search endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
feliperuhland committed Dec 4, 2019
1 parent a0b9c3d commit 901f857
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions docker/api/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,14 @@ def remove_image(self, image, force=False, noprune=False):
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.
Expand All @@ -509,8 +510,12 @@ def search(self, term):
: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
)

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/models_images_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def test_search(self):
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):
Expand Down

0 comments on commit 901f857

Please sign in to comment.