diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/api_image_test.py | 24 | ||||
-rw-r--r-- | tests/integration/models_images_test.py | 17 |
2 files changed, 39 insertions, 2 deletions
diff --git a/tests/integration/api_image_test.py b/tests/integration/api_image_test.py index 178c34e..ae93190 100644 --- a/tests/integration/api_image_test.py +++ b/tests/integration/api_image_test.py @@ -329,7 +329,7 @@ class PruneImagesTest(BaseAPIIntegrationTest): img_id = self.client.inspect_image('hello-world')['Id'] result = self.client.prune_images() assert img_id not in [ - img.get('Deleted') for img in result['ImagesDeleted'] + img.get('Deleted') for img in result.get('ImagesDeleted') or [] ] result = self.client.prune_images({'dangling': False}) assert result['SpaceReclaimed'] > 0 @@ -339,3 +339,25 @@ class PruneImagesTest(BaseAPIIntegrationTest): assert img_id in [ img.get('Deleted') for img in result['ImagesDeleted'] ] + + +class SaveLoadImagesTest(BaseAPIIntegrationTest): + @requires_api_version('1.23') + def test_get_image_load_image(self): + with tempfile.TemporaryFile() as f: + stream = self.client.get_image(BUSYBOX) + for chunk in stream: + f.write(chunk) + + f.seek(0) + result = self.client.load_image(f.read()) + + success = False + result_line = 'Loaded image: {}\n'.format(BUSYBOX) + for data in result: + print(data) + if 'stream' in data: + if data['stream'] == result_line: + success = True + break + assert success is True diff --git a/tests/integration/models_images_test.py b/tests/integration/models_images_test.py index 8840e15..2a28e12 100644 --- a/tests/integration/models_images_test.py +++ b/tests/integration/models_images_test.py @@ -1,9 +1,10 @@ import io +import tempfile import docker import pytest -from .base import BaseIntegrationTest, TEST_API_VERSION +from .base import BaseIntegrationTest, BUSYBOX, TEST_API_VERSION class ImageCollectionTest(BaseIntegrationTest): @@ -76,6 +77,20 @@ class ImageCollectionTest(BaseIntegrationTest): with pytest.raises(docker.errors.ImageLoadError): client.images.load('abc') + def test_save_and_load(self): + client = docker.from_env(version=TEST_API_VERSION) + image = client.images.get(BUSYBOX) + with tempfile.TemporaryFile() as f: + stream = image.save() + for chunk in stream: + f.write(chunk) + + f.seek(0) + result = client.images.load(f.read()) + + assert len(result) == 1 + assert result[0].id == image.id + class ImageTest(BaseIntegrationTest): |