diff options
author | Matt Bogosian <mtb19@columbia.edu> | 2015-05-17 09:25:38 -0700 |
---|---|---|
committer | Matt Bogosian <mtb19@columbia.edu> | 2015-05-17 17:39:25 -0700 |
commit | de2f58d818565dd3de28dee269dfc17c367306ef (patch) | |
tree | d53f21d666e30e100eee5fa788a92495e7bcdef4 | |
parent | f044b5e3f73c7bc0031beabb97aa8a5760b792c7 (diff) | |
download | docker-py-de2f58d818565dd3de28dee269dfc17c367306ef.tar.gz |
Fix #602. Raise ValueError on empty argument to inspect_{container,image}() methods.
-rw-r--r-- | docker/client.py | 2 | ||||
-rw-r--r-- | docker/utils/decorators.py | 2 | ||||
-rw-r--r-- | tests/test.py | 12 |
3 files changed, 16 insertions, 0 deletions
diff --git a/docker/client.py b/docker/client.py index 085dff4..63f8038 100644 --- a/docker/client.py +++ b/docker/client.py @@ -747,6 +747,8 @@ class Client(requests.Session): @check_resource def inspect_image(self, image): + if isinstance(image, dict): + image = image.get('Id') return self._result( self._get(self._url("/images/{0}/json".format(image))), True diff --git a/docker/utils/decorators.py b/docker/utils/decorators.py index 1ed0b6a..aa4f0c3 100644 --- a/docker/utils/decorators.py +++ b/docker/utils/decorators.py @@ -12,5 +12,7 @@ def check_resource(f): raise errors.NullResource( '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 wrapped diff --git a/tests/test.py b/tests/test.py index 9b90017..98bb03f 100644 --- a/tests/test.py +++ b/tests/test.py @@ -1782,6 +1782,12 @@ class DockerClientTest(Cleanup, base.BaseTestCase): except Exception as 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( url_prefix + 'containers/3cc2351ab11b/json', timeout=DEFAULT_TIMEOUT_SECONDS @@ -1953,6 +1959,12 @@ class DockerClientTest(Cleanup, base.BaseTestCase): except Exception as 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( url_prefix + 'images/test_image/json', timeout=DEFAULT_TIMEOUT_SECONDS |