Merge branch 'posita-raise-on-inspect-empty-string-602'

This commit is contained in:
Joffrey F 2015-05-20 14:47:27 -07:00
commit d600073cef
3 changed files with 26 additions and 5 deletions

View File

@ -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

View File

@ -8,9 +8,9 @@ def check_resource(f):
resource_id = kwargs.pop('container')
elif kwargs.get('image'):
resource_id = kwargs.pop('image')
else:
raise errors.NullResource(
'image or container param is undefined'
)
if not resource_id:
raise errors.NullResource(
'image or container param is undefined'
)
return f(self, resource_id, *args, **kwargs)
return wrapped

View File

@ -1781,12 +1781,21 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
self.client.inspect_container(fake_api.FAKE_CONTAINER_ID)
except Exception as e:
self.fail('Command should not raise exception: {0}'.format(e))
fake_request.assert_called_with(
url_prefix + 'containers/3cc2351ab11b/json',
timeout=DEFAULT_TIMEOUT_SECONDS
)
def test_inspect_container_empty_id(self):
try:
self.client.inspect_container('')
except docker.errors.NullResource as e:
self.assertEqual(
e.args[0], 'image or container param is undefined'
)
else:
self.fail('Command expected NullResource exception')
def test_container_stats(self):
try:
self.client.stats(fake_api.FAKE_CONTAINER_ID)
@ -1958,6 +1967,16 @@ class DockerClientTest(Cleanup, base.BaseTestCase):
timeout=DEFAULT_TIMEOUT_SECONDS
)
def test_inspect_image_empty_id(self):
try:
self.client.inspect_image('')
except docker.errors.NullResource as e:
self.assertEqual(
e.args[0], 'image or container param is undefined'
)
else:
self.fail('Command expected NullResource exception')
def test_insert_image(self):
try:
self.client.insert(fake_api.FAKE_IMAGE_NAME,