mirror of https://github.com/docker/docker-py.git
Merge pull request #236 from rail44/feature-support-get-and-load-image
Support get and load image
This commit is contained in:
commit
fb11abc8c6
|
@ -485,6 +485,12 @@ class Client(requests.Session):
|
|||
self._raise_for_status(res)
|
||||
return res.raw
|
||||
|
||||
def get_image(self, image):
|
||||
res = self._get(self._url("/images/{0}/get".format(image)),
|
||||
stream=True)
|
||||
self._raise_for_status(res)
|
||||
return res.raw
|
||||
|
||||
def history(self, image):
|
||||
res = self._get(self._url("/images/{0}/history".format(image)))
|
||||
self._raise_for_status(res)
|
||||
|
@ -571,6 +577,10 @@ class Client(requests.Session):
|
|||
|
||||
self._raise_for_status(res)
|
||||
|
||||
def load_image(self, data):
|
||||
res = self._post(self._url("/images/load"), data=data)
|
||||
self._raise_for_status(res)
|
||||
|
||||
def login(self, username, password=None, email=None, registry=None,
|
||||
reauth=False):
|
||||
# If we don't have any auth data so far, try reloading the config file
|
||||
|
|
|
@ -255,6 +255,18 @@ def delete_fake_remove_image():
|
|||
return status_code, response
|
||||
|
||||
|
||||
def get_fake_get_image():
|
||||
status_code = 200
|
||||
response = 'Byte Stream....'
|
||||
return status_code, response
|
||||
|
||||
|
||||
def post_fake_load_image():
|
||||
status_code = 200
|
||||
response = {'Id': FAKE_IMAGE_ID}
|
||||
return status_code, response
|
||||
|
||||
|
||||
def post_fake_commit():
|
||||
status_code = 200
|
||||
response = {'Id': FAKE_CONTAINER_ID}
|
||||
|
@ -324,6 +336,10 @@ fake_responses = {
|
|||
post_fake_image_create,
|
||||
'{1}/{0}/images/e9aa60c60128'.format(CURRENT_VERSION, prefix):
|
||||
delete_fake_remove_image,
|
||||
'{1}/{0}/images/e9aa60c60128/get'.format(CURRENT_VERSION, prefix):
|
||||
get_fake_get_image,
|
||||
'{1}/{0}/images/load'.format(CURRENT_VERSION, prefix):
|
||||
post_fake_load_image,
|
||||
'{1}/{0}/images/test_image/json'.format(CURRENT_VERSION, prefix):
|
||||
get_fake_inspect_image,
|
||||
'{1}/{0}/images/test_image/insert'.format(CURRENT_VERSION, prefix):
|
||||
|
|
|
@ -25,7 +25,7 @@ import docker
|
|||
import six
|
||||
|
||||
# FIXME: missing tests for
|
||||
# export; history; import_image; insert; port; push; tag
|
||||
# export; history; import_image; insert; port; push; tag; get; load
|
||||
|
||||
|
||||
class BaseTestCase(unittest.TestCase):
|
||||
|
|
|
@ -1226,6 +1226,30 @@ class DockerClientTest(unittest.TestCase):
|
|||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_get_image(self):
|
||||
try:
|
||||
self.client.get_image(fake_api.FAKE_IMAGE_ID)
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
fake_request.assert_called_with(
|
||||
url_prefix + 'images/e9aa60c60128/get',
|
||||
stream=True,
|
||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
def test_load_image(self):
|
||||
try:
|
||||
self.client.load_image('Byte Stream....')
|
||||
except Exception as e:
|
||||
self.fail('Command should not raise exception: {0}'.format(e))
|
||||
|
||||
fake_request.assert_called_with(
|
||||
url_prefix + 'images/load',
|
||||
data='Byte Stream....',
|
||||
timeout=docker.client.DEFAULT_TIMEOUT_SECONDS
|
||||
)
|
||||
|
||||
#################
|
||||
# BUILDER TESTS #
|
||||
#################
|
||||
|
|
Loading…
Reference in New Issue