Unverified Kaydet (Commit) 7339d770 authored tarafından Ben Firshman's avatar Ben Firshman

Move BaseTestCase to BaseIntegrationTest

Because two things called `BaseTestCase` is quite confusing.
I haven't bothered refactoring the other `BaseTestCase` because
that disappears anyway when we drop Python 2.6 support.
Signed-off-by: 's avatarBen Firshman <ben@firshman.co.uk>
üst 8cb186b6
import os import os
import os.path import os.path
import shutil
import tarfile import tarfile
import tempfile import tempfile
import unittest
import docker
import six
BUSYBOX = 'busybox:buildroot-2014.02'
EXEC_DRIVER = []
def make_tree(dirs, files): def make_tree(dirs, files):
...@@ -43,88 +36,3 @@ def untar_file(tardata, filename): ...@@ -43,88 +36,3 @@ def untar_file(tardata, filename):
result = f.read() result = f.read()
f.close() f.close()
return result return result
def docker_client(**kwargs):
return docker.Client(**docker_client_kwargs(**kwargs))
def docker_client_kwargs(**kwargs):
client_kwargs = docker.utils.kwargs_from_env(assert_hostname=False)
client_kwargs.update(kwargs)
return client_kwargs
class BaseTestCase(unittest.TestCase):
tmp_imgs = []
tmp_containers = []
tmp_folders = []
tmp_volumes = []
def setUp(self):
if six.PY2:
self.assertRegex = self.assertRegexpMatches
self.assertCountEqual = self.assertItemsEqual
self.client = docker_client(timeout=60)
self.tmp_imgs = []
self.tmp_containers = []
self.tmp_folders = []
self.tmp_volumes = []
self.tmp_networks = []
def tearDown(self):
for img in self.tmp_imgs:
try:
self.client.remove_image(img)
except docker.errors.APIError:
pass
for container in self.tmp_containers:
try:
self.client.stop(container, timeout=1)
self.client.remove_container(container)
except docker.errors.APIError:
pass
for network in self.tmp_networks:
try:
self.client.remove_network(network)
except docker.errors.APIError:
pass
for folder in self.tmp_folders:
shutil.rmtree(folder)
for volume in self.tmp_volumes:
try:
self.client.remove_volume(volume)
except docker.errors.APIError:
pass
self.client.close()
def run_container(self, *args, **kwargs):
container = self.client.create_container(*args, **kwargs)
self.tmp_containers.append(container)
self.client.start(container)
exitcode = self.client.wait(container)
if exitcode != 0:
output = self.client.logs(container)
raise Exception(
"Container exited with code {}:\n{}"
.format(exitcode, output))
return container
def create_and_start(self, image='busybox', command='top', **kwargs):
container = self.client.create_container(
image=image, command=command, **kwargs)
self.tmp_containers.append(container)
self.client.start(container)
return container
def execute(self, container, cmd, exit_code=0, **kwargs):
exc = self.client.exec_create(container, cmd, **kwargs)
output = self.client.exec_start(exc)
actual_exit_code = self.client.exec_inspect(exc)['ExitCode']
msg = "Expected `{}` to exit with code {} but returned {}:\n{}".format(
" ".join(cmd), exit_code, actual_exit_code, output)
assert actual_exit_code == exit_code, msg
...@@ -6,11 +6,12 @@ import unittest ...@@ -6,11 +6,12 @@ import unittest
import warnings import warnings
import docker import docker
from docker.utils import kwargs_from_env
from .. import helpers from .base import BaseIntegrationTest, BUSYBOX
class InformationTest(helpers.BaseTestCase): class InformationTest(BaseIntegrationTest):
def test_version(self): def test_version(self):
res = self.client.version() res = self.client.version()
self.assertIn('GoVersion', res) self.assertIn('GoVersion', res)
...@@ -24,19 +25,19 @@ class InformationTest(helpers.BaseTestCase): ...@@ -24,19 +25,19 @@ class InformationTest(helpers.BaseTestCase):
self.assertIn('Debug', res) self.assertIn('Debug', res)
def test_search(self): def test_search(self):
self.client = helpers.docker_client(timeout=10) client = docker.from_env(timeout=10)
res = self.client.search('busybox') res = client.search('busybox')
self.assertTrue(len(res) >= 1) self.assertTrue(len(res) >= 1)
base_img = [x for x in res if x['name'] == 'busybox'] base_img = [x for x in res if x['name'] == 'busybox']
self.assertEqual(len(base_img), 1) self.assertEqual(len(base_img), 1)
self.assertIn('description', base_img[0]) self.assertIn('description', base_img[0])
class LinkTest(helpers.BaseTestCase): class LinkTest(BaseIntegrationTest):
def test_remove_link(self): def test_remove_link(self):
# Create containers # Create containers
container1 = self.client.create_container( container1 = self.client.create_container(
helpers.BUSYBOX, 'cat', detach=True, stdin_open=True BUSYBOX, 'cat', detach=True, stdin_open=True
) )
container1_id = container1['Id'] container1_id = container1['Id']
self.tmp_containers.append(container1_id) self.tmp_containers.append(container1_id)
...@@ -48,7 +49,7 @@ class LinkTest(helpers.BaseTestCase): ...@@ -48,7 +49,7 @@ class LinkTest(helpers.BaseTestCase):
link_alias = 'mylink' link_alias = 'mylink'
container2 = self.client.create_container( container2 = self.client.create_container(
helpers.BUSYBOX, 'cat', host_config=self.client.create_host_config( BUSYBOX, 'cat', host_config=self.client.create_host_config(
links={link_path: link_alias} links={link_path: link_alias}
) )
) )
...@@ -74,7 +75,7 @@ class LinkTest(helpers.BaseTestCase): ...@@ -74,7 +75,7 @@ class LinkTest(helpers.BaseTestCase):
self.assertEqual(len(retrieved), 2) self.assertEqual(len(retrieved), 2)
class LoadConfigTest(helpers.BaseTestCase): class LoadConfigTest(BaseIntegrationTest):
def test_load_legacy_config(self): def test_load_legacy_config(self):
folder = tempfile.mkdtemp() folder = tempfile.mkdtemp()
self.tmp_folders.append(folder) self.tmp_folders.append(folder)
...@@ -113,7 +114,7 @@ class LoadConfigTest(helpers.BaseTestCase): ...@@ -113,7 +114,7 @@ class LoadConfigTest(helpers.BaseTestCase):
class AutoDetectVersionTest(unittest.TestCase): class AutoDetectVersionTest(unittest.TestCase):
def test_client_init(self): def test_client_init(self):
client = helpers.docker_client(version='auto') client = docker.from_env(version='auto')
client_version = client._version client_version = client._version
api_version = client.version(api_version=False)['ApiVersion'] api_version = client.version(api_version=False)['ApiVersion']
self.assertEqual(client_version, api_version) self.assertEqual(client_version, api_version)
...@@ -122,7 +123,7 @@ class AutoDetectVersionTest(unittest.TestCase): ...@@ -122,7 +123,7 @@ class AutoDetectVersionTest(unittest.TestCase):
client.close() client.close()
def test_auto_client(self): def test_auto_client(self):
client = docker.AutoVersionClient(**helpers.docker_client_kwargs()) client = docker.AutoVersionClient(**kwargs_from_env())
client_version = client._version client_version = client._version
api_version = client.version(api_version=False)['ApiVersion'] api_version = client.version(api_version=False)['ApiVersion']
self.assertEqual(client_version, api_version) self.assertEqual(client_version, api_version)
...@@ -130,9 +131,7 @@ class AutoDetectVersionTest(unittest.TestCase): ...@@ -130,9 +131,7 @@ class AutoDetectVersionTest(unittest.TestCase):
self.assertEqual(client_version, api_version_2) self.assertEqual(client_version, api_version_2)
client.close() client.close()
with self.assertRaises(docker.errors.DockerException): with self.assertRaises(docker.errors.DockerException):
docker.AutoVersionClient( docker.AutoVersionClient(version='1.11', **kwargs_from_env())
**helpers.docker_client_kwargs(version='1.11')
)
class ConnectionTimeoutTest(unittest.TestCase): class ConnectionTimeoutTest(unittest.TestCase):
...@@ -167,7 +166,7 @@ class UnixconnTest(unittest.TestCase): ...@@ -167,7 +166,7 @@ class UnixconnTest(unittest.TestCase):
with warnings.catch_warnings(record=True) as w: with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always') warnings.simplefilter('always')
client = helpers.docker_client() client = docker.from_env()
client.images() client.images()
client.close() client.close()
del client del client
......
import shutil
import unittest
import docker
import six
BUSYBOX = 'busybox:buildroot-2014.02'
class BaseIntegrationTest(unittest.TestCase):
"""
A base class for integration test cases.
It sets up a Docker client and cleans up the Docker server after itself.
"""
tmp_imgs = []
tmp_containers = []
tmp_folders = []
tmp_volumes = []
def setUp(self):
if six.PY2:
self.assertRegex = self.assertRegexpMatches
self.assertCountEqual = self.assertItemsEqual
self.client = docker.from_env(timeout=60)
self.tmp_imgs = []
self.tmp_containers = []
self.tmp_folders = []
self.tmp_volumes = []
self.tmp_networks = []
def tearDown(self):
for img in self.tmp_imgs:
try:
self.client.remove_image(img)
except docker.errors.APIError:
pass
for container in self.tmp_containers:
try:
self.client.stop(container, timeout=1)
self.client.remove_container(container)
except docker.errors.APIError:
pass
for network in self.tmp_networks:
try:
self.client.remove_network(network)
except docker.errors.APIError:
pass
for folder in self.tmp_folders:
shutil.rmtree(folder)
for volume in self.tmp_volumes:
try:
self.client.remove_volume(volume)
except docker.errors.APIError:
pass
self.client.close()
def run_container(self, *args, **kwargs):
container = self.client.create_container(*args, **kwargs)
self.tmp_containers.append(container)
self.client.start(container)
exitcode = self.client.wait(container)
if exitcode != 0:
output = self.client.logs(container)
raise Exception(
"Container exited with code {}:\n{}"
.format(exitcode, output))
return container
def create_and_start(self, image='busybox', command='top', **kwargs):
container = self.client.create_container(
image=image, command=command, **kwargs)
self.tmp_containers.append(container)
self.client.start(container)
return container
def execute(self, container, cmd, exit_code=0, **kwargs):
exc = self.client.exec_create(container, cmd, **kwargs)
output = self.client.exec_start(exc)
actual_exit_code = self.client.exec_inspect(exc)['ExitCode']
msg = "Expected `{}` to exit with code {} but returned {}:\n{}".format(
" ".join(cmd), exit_code, actual_exit_code, output)
assert actual_exit_code == exit_code, msg
...@@ -8,11 +8,11 @@ import six ...@@ -8,11 +8,11 @@ import six
from docker import errors from docker import errors
from .. import helpers
from ..base import requires_api_version from ..base import requires_api_version
from .base import BaseIntegrationTest
class BuildTest(helpers.BaseTestCase): class BuildTest(BaseIntegrationTest):
def test_build_streaming(self): def test_build_streaming(self):
script = io.BytesIO('\n'.join([ script = io.BytesIO('\n'.join([
'FROM busybox', 'FROM busybox',
......
...@@ -7,14 +7,13 @@ import warnings ...@@ -7,14 +7,13 @@ import warnings
import docker.errors import docker.errors
import pytest import pytest
from ..helpers import BUSYBOX from .base import BUSYBOX
from ..helpers import docker_client
@pytest.fixture(autouse=True, scope='session') @pytest.fixture(autouse=True, scope='session')
def setup_test_session(): def setup_test_session():
warnings.simplefilter('error') warnings.simplefilter('error')
c = docker_client() c = docker.from_env()
try: try:
c.inspect_image(BUSYBOX) c.inspect_image(BUSYBOX)
except docker.errors.NotFound: except docker.errors.NotFound:
......
...@@ -10,11 +10,10 @@ import six ...@@ -10,11 +10,10 @@ import six
from ..base import requires_api_version from ..base import requires_api_version
from .. import helpers from .. import helpers
from .base import BaseIntegrationTest, BUSYBOX
BUSYBOX = helpers.BUSYBOX
class ListContainersTest(BaseIntegrationTest):
class ListContainersTest(helpers.BaseTestCase):
def test_list_containers(self): def test_list_containers(self):
res0 = self.client.containers(all=True) res0 = self.client.containers(all=True)
size = len(res0) size = len(res0)
...@@ -34,7 +33,7 @@ class ListContainersTest(helpers.BaseTestCase): ...@@ -34,7 +33,7 @@ class ListContainersTest(helpers.BaseTestCase):
self.assertIn('Status', retrieved) self.assertIn('Status', retrieved)
class CreateContainerTest(helpers.BaseTestCase): class CreateContainerTest(BaseIntegrationTest):
def test_create(self): def test_create(self):
res = self.client.create_container(BUSYBOX, 'true') res = self.client.create_container(BUSYBOX, 'true')
...@@ -398,7 +397,7 @@ class CreateContainerTest(helpers.BaseTestCase): ...@@ -398,7 +397,7 @@ class CreateContainerTest(helpers.BaseTestCase):
assert config['HostConfig']['Tmpfs'] == tmpfs assert config['HostConfig']['Tmpfs'] == tmpfs
class VolumeBindTest(helpers.BaseTestCase): class VolumeBindTest(BaseIntegrationTest):
def setUp(self): def setUp(self):
super(VolumeBindTest, self).setUp() super(VolumeBindTest, self).setUp()
...@@ -487,7 +486,7 @@ class VolumeBindTest(helpers.BaseTestCase): ...@@ -487,7 +486,7 @@ class VolumeBindTest(helpers.BaseTestCase):
@requires_api_version('1.20') @requires_api_version('1.20')
class ArchiveTest(helpers.BaseTestCase): class ArchiveTest(BaseIntegrationTest):
def test_get_file_archive_from_container(self): def test_get_file_archive_from_container(self):
data = 'The Maid and the Pocket Watch of Blood' data = 'The Maid and the Pocket Watch of Blood'
ctnr = self.client.create_container( ctnr = self.client.create_container(
...@@ -567,7 +566,7 @@ class ArchiveTest(helpers.BaseTestCase): ...@@ -567,7 +566,7 @@ class ArchiveTest(helpers.BaseTestCase):
self.assertIn('bar/', results) self.assertIn('bar/', results)
class RenameContainerTest(helpers.BaseTestCase): class RenameContainerTest(BaseIntegrationTest):
def test_rename_container(self): def test_rename_container(self):
version = self.client.version()['Version'] version = self.client.version()['Version']
name = 'hong_meiling' name = 'hong_meiling'
...@@ -583,7 +582,7 @@ class RenameContainerTest(helpers.BaseTestCase): ...@@ -583,7 +582,7 @@ class RenameContainerTest(helpers.BaseTestCase):
self.assertEqual('/{0}'.format(name), inspect['Name']) self.assertEqual('/{0}'.format(name), inspect['Name'])
class StartContainerTest(helpers.BaseTestCase): class StartContainerTest(BaseIntegrationTest):
def test_start_container(self): def test_start_container(self):
res = self.client.create_container(BUSYBOX, 'true') res = self.client.create_container(BUSYBOX, 'true')
self.assertIn('Id', res) self.assertIn('Id', res)
...@@ -637,7 +636,7 @@ class StartContainerTest(helpers.BaseTestCase): ...@@ -637,7 +636,7 @@ class StartContainerTest(helpers.BaseTestCase):
self.assertEqual(exitcode, 0, msg=cmd) self.assertEqual(exitcode, 0, msg=cmd)
class WaitTest(helpers.BaseTestCase): class WaitTest(BaseIntegrationTest):
def test_wait(self): def test_wait(self):
res = self.client.create_container(BUSYBOX, ['sleep', '3']) res = self.client.create_container(BUSYBOX, ['sleep', '3'])
id = res['Id'] id = res['Id']
...@@ -665,7 +664,7 @@ class WaitTest(helpers.BaseTestCase): ...@@ -665,7 +664,7 @@ class WaitTest(helpers.BaseTestCase):
self.assertEqual(inspect['State']['ExitCode'], exitcode) self.assertEqual(inspect['State']['ExitCode'], exitcode)
class LogsTest(helpers.BaseTestCase): class LogsTest(BaseIntegrationTest):
def test_logs(self): def test_logs(self):
snippet = 'Flowering Nights (Sakuya Iyazoi)' snippet = 'Flowering Nights (Sakuya Iyazoi)'
container = self.client.create_container( container = self.client.create_container(
...@@ -737,7 +736,7 @@ Line2''' ...@@ -737,7 +736,7 @@ Line2'''
self.assertEqual(logs, ''.encode(encoding='ascii')) self.assertEqual(logs, ''.encode(encoding='ascii'))
class DiffTest(helpers.BaseTestCase): class DiffTest(BaseIntegrationTest):
def test_diff(self): def test_diff(self):
container = self.client.create_container(BUSYBOX, ['touch', '/test']) container = self.client.create_container(BUSYBOX, ['touch', '/test'])
id = container['Id'] id = container['Id']
...@@ -765,7 +764,7 @@ class DiffTest(helpers.BaseTestCase): ...@@ -765,7 +764,7 @@ class DiffTest(helpers.BaseTestCase):
self.assertEqual(test_diff[0]['Kind'], 1) self.assertEqual(test_diff[0]['Kind'], 1)
class StopTest(helpers.BaseTestCase): class StopTest(BaseIntegrationTest):
def test_stop(self): def test_stop(self):
container = self.client.create_container(BUSYBOX, ['sleep', '9999']) container = self.client.create_container(BUSYBOX, ['sleep', '9999'])
id = container['Id'] id = container['Id']
...@@ -792,7 +791,7 @@ class StopTest(helpers.BaseTestCase): ...@@ -792,7 +791,7 @@ class StopTest(helpers.BaseTestCase):
self.assertEqual(state['Running'], False) self.assertEqual(state['Running'], False)
class KillTest(helpers.BaseTestCase): class KillTest(BaseIntegrationTest):
def test_kill(self): def test_kill(self):
container = self.client.create_container(BUSYBOX, ['sleep', '9999']) container = self.client.create_container(BUSYBOX, ['sleep', '9999'])
id = container['Id'] id = container['Id']
...@@ -868,7 +867,7 @@ class KillTest(helpers.BaseTestCase): ...@@ -868,7 +867,7 @@ class KillTest(helpers.BaseTestCase):
self.assertEqual(state['Running'], False, state) self.assertEqual(state['Running'], False, state)
class PortTest(helpers.BaseTestCase): class PortTest(BaseIntegrationTest):
def test_port(self): def test_port(self):
port_bindings = { port_bindings = {
...@@ -899,7 +898,7 @@ class PortTest(helpers.BaseTestCase): ...@@ -899,7 +898,7 @@ class PortTest(helpers.BaseTestCase):
self.client.kill(id) self.client.kill(id)
class ContainerTopTest(helpers.BaseTestCase): class ContainerTopTest(BaseIntegrationTest):
def test_top(self): def test_top(self):
container = self.client.create_container( container = self.client.create_container(
BUSYBOX, ['sleep', '60']) BUSYBOX, ['sleep', '60'])
...@@ -934,7 +933,7 @@ class ContainerTopTest(helpers.BaseTestCase): ...@@ -934,7 +933,7 @@ class ContainerTopTest(helpers.BaseTestCase):
self.client.kill(id) self.client.kill(id)
class RestartContainerTest(helpers.BaseTestCase): class RestartContainerTest(BaseIntegrationTest):
def test_restart(self): def test_restart(self):
container = self.client.create_container(BUSYBOX, ['sleep', '9999']) container = self.client.create_container(BUSYBOX, ['sleep', '9999'])
id = container['Id'] id = container['Id']
...@@ -975,7 +974,7 @@ class RestartContainerTest(helpers.BaseTestCase): ...@@ -975,7 +974,7 @@ class RestartContainerTest(helpers.BaseTestCase):
self.client.kill(id) self.client.kill(id)
class RemoveContainerTest(helpers.BaseTestCase): class RemoveContainerTest(BaseIntegrationTest):
def test_remove(self): def test_remove(self):
container = self.client.create_container(BUSYBOX, ['true']) container = self.client.create_container(BUSYBOX, ['true'])
id = container['Id'] id = container['Id']
...@@ -997,7 +996,7 @@ class RemoveContainerTest(helpers.BaseTestCase): ...@@ -997,7 +996,7 @@ class RemoveContainerTest(helpers.BaseTestCase):
self.assertEqual(len(res), 0) self.assertEqual(len(res), 0)
class AttachContainerTest(helpers.BaseTestCase): class AttachContainerTest(BaseIntegrationTest):
def test_run_container_streaming(self): def test_run_container_streaming(self):
container = self.client.create_container(BUSYBOX, '/bin/sh', container = self.client.create_container(BUSYBOX, '/bin/sh',
detach=True, stdin_open=True) detach=True, stdin_open=True)
...@@ -1028,7 +1027,7 @@ class AttachContainerTest(helpers.BaseTestCase): ...@@ -1028,7 +1027,7 @@ class AttachContainerTest(helpers.BaseTestCase):
self.assertEqual(data.decode('utf-8'), line) self.assertEqual(data.decode('utf-8'), line)
class PauseTest(helpers.BaseTestCase): class PauseTest(BaseIntegrationTest):
def test_pause_unpause(self): def test_pause_unpause(self):
container = self.client.create_container(BUSYBOX, ['sleep', '9999']) container = self.client.create_container(BUSYBOX, ['sleep', '9999'])
id = container['Id'] id = container['Id']
...@@ -1057,7 +1056,7 @@ class PauseTest(helpers.BaseTestCase): ...@@ -1057,7 +1056,7 @@ class PauseTest(helpers.BaseTestCase):
self.assertEqual(state['Paused'], False) self.assertEqual(state['Paused'], False)
class GetContainerStatsTest(helpers.BaseTestCase): class GetContainerStatsTest(BaseIntegrationTest):
@requires_api_version('1.19') @requires_api_version('1.19')
def test_get_container_stats_no_stream(self): def test_get_container_stats_no_stream(self):
container = self.client.create_container( container = self.client.create_container(
...@@ -1088,7 +1087,7 @@ class GetContainerStatsTest(helpers.BaseTestCase): ...@@ -1088,7 +1087,7 @@ class GetContainerStatsTest(helpers.BaseTestCase):
self.assertIn(key, chunk) self.assertIn(key, chunk)
class ContainerUpdateTest(helpers.BaseTestCase): class ContainerUpdateTest(BaseIntegrationTest):
@requires_api_version('1.22') @requires_api_version('1.22')
def test_update_container(self): def test_update_container(self):
old_mem_limit = 400 * 1024 * 1024 old_mem_limit = 400 * 1024 * 1024
...@@ -1135,7 +1134,7 @@ class ContainerUpdateTest(helpers.BaseTestCase): ...@@ -1135,7 +1134,7 @@ class ContainerUpdateTest(helpers.BaseTestCase):
) )
class ContainerCPUTest(helpers.BaseTestCase): class ContainerCPUTest(BaseIntegrationTest):
@requires_api_version('1.18') @requires_api_version('1.18')
def test_container_cpu_shares(self): def test_container_cpu_shares(self):
cpu_shares = 512 cpu_shares = 512
......
from docker.errors import APIError from docker.errors import APIError
from .. import helpers from .base import BaseIntegrationTest, BUSYBOX
class ErrorsTest(helpers.BaseTestCase): class ErrorsTest(BaseIntegrationTest):
def test_api_error_parses_json(self): def test_api_error_parses_json(self):
container = self.client.create_container( container = self.client.create_container(BUSYBOX, ['sleep', '10'])
helpers.BUSYBOX,
['sleep', '10']
)
self.client.start(container['Id']) self.client.start(container['Id'])
with self.assertRaises(APIError) as cm: with self.assertRaises(APIError) as cm:
self.client.remove_container(container['Id']) self.client.remove_container(container['Id'])
......
from docker.utils.socket import next_frame_size from docker.utils.socket import next_frame_size
from docker.utils.socket import read_exactly from docker.utils.socket import read_exactly
from .. import helpers from .base import BaseIntegrationTest, BUSYBOX
BUSYBOX = helpers.BUSYBOX
class ExecTest(BaseIntegrationTest):
class ExecTest(helpers.BaseTestCase):
def test_execute_command(self): def test_execute_command(self):
container = self.client.create_container(BUSYBOX, 'cat', container = self.client.create_container(BUSYBOX, 'cat',
detach=True, stdin_open=True) detach=True, stdin_open=True)
......
...@@ -14,12 +14,10 @@ from six.moves import socketserver ...@@ -14,12 +14,10 @@ from six.moves import socketserver
import docker import docker
from .. import helpers from .base import BaseIntegrationTest, BUSYBOX
BUSYBOX = helpers.BUSYBOX
class ListImagesTest(BaseIntegrationTest):
class ListImagesTest(helpers.BaseTestCase):
def test_images(self): def test_images(self):
res1 = self.client.images(all=True) res1 = self.client.images(all=True)
self.assertIn('Id', res1[0]) self.assertIn('Id', res1[0])
...@@ -37,7 +35,7 @@ class ListImagesTest(helpers.BaseTestCase): ...@@ -37,7 +35,7 @@ class ListImagesTest(helpers.BaseTestCase):
self.assertEqual(type(res1[0]), six.text_type) self.assertEqual(type(res1[0]), six.text_type)
class PullImageTest(helpers.BaseTestCase): class PullImageTest(BaseIntegrationTest):
def test_pull(self): def test_pull(self):
try: try:
self.client.remove_image('hello-world') self.client.remove_image('hello-world')
...@@ -70,7 +68,7 @@ class PullImageTest(helpers.BaseTestCase): ...@@ -70,7 +68,7 @@ class PullImageTest(helpers.BaseTestCase):
self.assertIn('Id', img_info) self.assertIn('Id', img_info)
class CommitTest(helpers.BaseTestCase): class CommitTest(BaseIntegrationTest):
def test_commit(self): def test_commit(self):
container = self.client.create_container(BUSYBOX, ['touch', '/test']) container = self.client.create_container(BUSYBOX, ['touch', '/test'])
id = container['Id'] id = container['Id']
...@@ -105,7 +103,7 @@ class CommitTest(helpers.BaseTestCase): ...@@ -105,7 +103,7 @@ class CommitTest(helpers.BaseTestCase):
assert img['Config']['Cmd'] == ['bash'] assert img['Config']['Cmd'] == ['bash']
class RemoveImageTest(helpers.BaseTestCase): class RemoveImageTest(BaseIntegrationTest):
def test_remove(self): def test_remove(self):
container = self.client.create_container(BUSYBOX, ['touch', '/test']) container = self.client.create_container(BUSYBOX, ['touch', '/test'])
id = container['Id'] id = container['Id']
...@@ -121,7 +119,7 @@ class RemoveImageTest(helpers.BaseTestCase): ...@@ -121,7 +119,7 @@ class RemoveImageTest(helpers.BaseTestCase):
self.assertEqual(len(res), 0) self.assertEqual(len(res), 0)
class ImportImageTest(helpers.BaseTestCase): class ImportImageTest(BaseIntegrationTest):
'''Base class for `docker import` test cases.''' '''Base class for `docker import` test cases.'''
TAR_SIZE = 512 * 1024 TAR_SIZE = 512 * 1024
......
...@@ -5,11 +5,11 @@ from docker.utils import create_ipam_config ...@@ -5,11 +5,11 @@ from docker.utils import create_ipam_config
from docker.utils import create_ipam_pool from docker.utils import create_ipam_pool
import pytest import pytest
from .. import helpers
from ..base import requires_api_version from ..base import requires_api_version
from .base import BaseIntegrationTest
class TestNetworks(helpers.BaseTestCase): class TestNetworks(BaseIntegrationTest):
def create_network(self, *args, **kwargs): def create_network(self, *args, **kwargs):
net_name = u'dockerpy{}'.format(random.getrandbits(24))[:14] net_name = u'dockerpy{}'.format(random.getrandbits(24))[:14]
net_id = self.client.create_network(net_name, *args, **kwargs)['Id'] net_id = self.client.create_network(net_name, *args, **kwargs)['Id']
......
...@@ -4,12 +4,10 @@ import random ...@@ -4,12 +4,10 @@ import random
import docker import docker
import six import six
from .. import helpers from .base import BaseIntegrationTest, BUSYBOX
BUSYBOX = helpers.BUSYBOX
class TestRegressions(BaseIntegrationTest):
class TestRegressions(helpers.BaseTestCase):
def test_443_handle_nonchunked_response_in_stream(self): def test_443_handle_nonchunked_response_in_stream(self):
dfile = io.BytesIO() dfile = io.BytesIO()
with self.assertRaises(docker.errors.APIError) as exc: with self.assertRaises(docker.errors.APIError) as exc:
......
...@@ -3,13 +3,10 @@ import random ...@@ -3,13 +3,10 @@ import random
import docker import docker
from ..base import requires_api_version from ..base import requires_api_version
from .. import helpers from .base import BaseIntegrationTest
BUSYBOX = helpers.BUSYBOX class ServiceTest(BaseIntegrationTest):
class ServiceTest(helpers.BaseTestCase):
def setUp(self): def setUp(self):
super(ServiceTest, self).setUp() super(ServiceTest, self).setUp()
self.client.leave_swarm(force=True) self.client.leave_swarm(force=True)
......
...@@ -2,13 +2,10 @@ import docker ...@@ -2,13 +2,10 @@ import docker
import pytest import pytest
from ..base import requires_api_version from ..base import requires_api_version
from .. import helpers from .base import BaseIntegrationTest
BUSYBOX = helpers.BUSYBOX class SwarmTest(BaseIntegrationTest):
class SwarmTest(helpers.BaseTestCase):
def setUp(self): def setUp(self):
super(SwarmTest, self).setUp() super(SwarmTest, self).setUp()
self.client.leave_swarm(force=True) self.client.leave_swarm(force=True)
......
...@@ -3,10 +3,11 @@ import pytest ...@@ -3,10 +3,11 @@ import pytest
from .. import helpers from .. import helpers
from ..base import requires_api_version from ..base import requires_api_version
from .base import BaseIntegrationTest
@requires_api_version('1.21') @requires_api_version('1.21')
class TestVolumes(helpers.BaseTestCase): class TestVolumes(BaseIntegrationTest):
def test_create_volume(self): def test_create_volume(self):
name = 'perfectcherryblossom' name = 'perfectcherryblossom'
self.tmp_volumes.append(name) self.tmp_volumes.append(name)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment