summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Ruhland <felipe.ruhland@gmail.com>2019-12-04 19:44:27 -0300
committerFelipe Ruhland <felipe.ruhland@gmail.com>2021-02-24 23:42:20 +0100
commit7d316641a3da5ece9a29471390ef965d13b160b7 (patch)
treeafe61df26cae4352f4ccc13212066964f99e577a
parentd09fe8d22578f7dc2ac2e6dceb343ac1b0c8497a (diff)
downloaddocker-py-7d316641a3da5ece9a29471390ef965d13b160b7.tar.gz
Add limit parameter to image search endpoint
Signed-off-by: Felipe Ruhland <felipe.ruhland@gmail.com>
-rw-r--r--docker/api/image.py9
-rw-r--r--tests/unit/models_images_test.py5
2 files changed, 12 insertions, 2 deletions
diff --git a/docker/api/image.py b/docker/api/image.py
index 56c5448..4658cde 100644
--- a/docker/api/image.py
+++ b/docker/api/image.py
@@ -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
)
diff --git a/tests/unit/models_images_test.py b/tests/unit/models_images_test.py
index e3d070c..f3ca0be 100644
--- a/tests/unit/models_images_test.py
+++ b/tests/unit/models_images_test.py
@@ -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):