Skip to content

Commit 86297c8

Browse files
committed
Merge branch 'raise-on-inspect-empty-string-602' of https://github.com/posita/docker-py into posita-raise-on-inspect-empty-string-602
2 parents 4aa2fa6 + de2f58d commit 86297c8

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

docker/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ def inspect_container(self, container):
747747

748748
@check_resource
749749
def inspect_image(self, image):
750+
if isinstance(image, dict):
751+
image = image.get('Id')
750752
return self._result(
751753
self._get(self._url("/images/{0}/json".format(image))),
752754
True

docker/utils/decorators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ def wrapped(self, resource_id=None, *args, **kwargs):
1212
raise errors.NullResource(
1313
'image or container param is undefined'
1414
)
15+
if not resource_id:
16+
raise ValueError('image or container param is empty')
1517
return f(self, resource_id, *args, **kwargs)
1618
return wrapped

tests/test.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,6 +1782,12 @@ def test_inspect_container(self):
17821782
except Exception as e:
17831783
self.fail('Command should not raise exception: {0}'.format(e))
17841784

1785+
try:
1786+
self.client.inspect_container('')
1787+
except ValueError as e:
1788+
self.assertEqual(e.args[0],
1789+
'image or container param is empty')
1790+
17851791
fake_request.assert_called_with(
17861792
url_prefix + 'containers/3cc2351ab11b/json',
17871793
timeout=DEFAULT_TIMEOUT_SECONDS
@@ -1953,6 +1959,12 @@ def test_inspect_image(self):
19531959
except Exception as e:
19541960
self.fail('Command should not raise exception: {0}'.format(e))
19551961

1962+
try:
1963+
self.client.inspect_image('')
1964+
except ValueError as e:
1965+
self.assertEqual(e.args[0],
1966+
'image or container param is empty')
1967+
19561968
fake_request.assert_called_with(
19571969
url_prefix + 'images/test_image/json',
19581970
timeout=DEFAULT_TIMEOUT_SECONDS

0 commit comments

Comments
 (0)