mirror of https://github.com/docker/docker-py.git
Fix #602. Raise ValueError on empty argument to inspect_{container,image}() methods.
This commit is contained in:
parent
f044b5e3f7
commit
de2f58d818
|
@ -747,6 +747,8 @@ class Client(requests.Session):
|
||||||
|
|
||||||
@check_resource
|
@check_resource
|
||||||
def inspect_image(self, image):
|
def inspect_image(self, image):
|
||||||
|
if isinstance(image, dict):
|
||||||
|
image = image.get('Id')
|
||||||
return self._result(
|
return self._result(
|
||||||
self._get(self._url("/images/{0}/json".format(image))),
|
self._get(self._url("/images/{0}/json".format(image))),
|
||||||
True
|
True
|
||||||
|
|
|
@ -12,5 +12,7 @@ def check_resource(f):
|
||||||
raise errors.NullResource(
|
raise errors.NullResource(
|
||||||
'image or container param is undefined'
|
'image or container param is undefined'
|
||||||
)
|
)
|
||||||
|
if not resource_id:
|
||||||
|
raise ValueError('image or container param is empty')
|
||||||
return f(self, resource_id, *args, **kwargs)
|
return f(self, resource_id, *args, **kwargs)
|
||||||
return wrapped
|
return wrapped
|
||||||
|
|
|
@ -1782,6 +1782,12 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.client.inspect_container('')
|
||||||
|
except ValueError as e:
|
||||||
|
self.assertEqual(e.args[0],
|
||||||
|
'image or container param is empty')
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
url_prefix + 'containers/3cc2351ab11b/json',
|
url_prefix + 'containers/3cc2351ab11b/json',
|
||||||
timeout=DEFAULT_TIMEOUT_SECONDS
|
timeout=DEFAULT_TIMEOUT_SECONDS
|
||||||
|
@ -1953,6 +1959,12 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.client.inspect_image('')
|
||||||
|
except ValueError as e:
|
||||||
|
self.assertEqual(e.args[0],
|
||||||
|
'image or container param is empty')
|
||||||
|
|
||||||
fake_request.assert_called_with(
|
fake_request.assert_called_with(
|
||||||
url_prefix + 'images/test_image/json',
|
url_prefix + 'images/test_image/json',
|
||||||
timeout=DEFAULT_TIMEOUT_SECONDS
|
timeout=DEFAULT_TIMEOUT_SECONDS
|
||||||
|
|
Loading…
Reference in New Issue