summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/api_build_test.py11
-rw-r--r--tests/unit/api_container_test.py60
-rw-r--r--tests/unit/api_image_test.py20
-rw-r--r--tests/unit/api_network_test.py7
-rw-r--r--tests/unit/api_test.py1
-rw-r--r--tests/unit/api_volume_test.py7
-rw-r--r--tests/unit/dockertypes_test.py48
-rw-r--r--tests/unit/fake_api.py39
8 files changed, 36 insertions, 157 deletions
diff --git a/tests/unit/api_build_test.py b/tests/unit/api_build_test.py
index b20daea..a7f34fd 100644
--- a/tests/unit/api_build_test.py
+++ b/tests/unit/api_build_test.py
@@ -31,17 +31,6 @@ class BuildTest(BaseAPIClientTest):
self.client.build(fileobj=script, pull=True)
- def test_build_container_stream(self):
- script = io.BytesIO('\n'.join([
- 'FROM busybox',
- 'RUN mkdir -p /tmp/test',
- 'EXPOSE 8080',
- 'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz'
- ' /tmp/silence.tar.gz'
- ]).encode('ascii'))
-
- self.client.build(fileobj=script, stream=True)
-
def test_build_container_custom_context(self):
script = io.BytesIO('\n'.join([
'FROM busybox',
diff --git a/tests/unit/api_container_test.py b/tests/unit/api_container_test.py
index 3cb718a..c33f129 100644
--- a/tests/unit/api_container_test.py
+++ b/tests/unit/api_container_test.py
@@ -219,24 +219,6 @@ class CreateContainerTest(BaseAPIClientTest):
''')
assert args[1]['headers'] == {'Content-Type': 'application/json'}
- def test_create_container_with_cpu_shares(self):
- with pytest.deprecated_call():
- self.client.create_container('busybox', 'ls', cpu_shares=5)
-
- args = fake_request.call_args
- assert args[0][1] == url_prefix + 'containers/create'
- assert json.loads(args[1]['data']) == json.loads('''
- {"Tty": false, "Image": "busybox",
- "Cmd": ["ls"], "AttachStdin": false,
- "AttachStderr": true,
- "AttachStdout": true, "OpenStdin": false,
- "StdinOnce": false,
- "NetworkDisabled": false,
- "CpuShares": 5}
- ''')
- assert args[1]['headers'] == {'Content-Type': 'application/json'}
-
- @requires_api_version('1.18')
def test_create_container_with_host_config_cpu_shares(self):
self.client.create_container(
'busybox', 'ls', host_config=self.client.create_host_config(
@@ -261,25 +243,6 @@ class CreateContainerTest(BaseAPIClientTest):
''')
assert args[1]['headers'] == {'Content-Type': 'application/json'}
- def test_create_container_with_cpuset(self):
- with pytest.deprecated_call():
- self.client.create_container('busybox', 'ls', cpuset='0,1')
-
- args = fake_request.call_args
- assert args[0][1] == url_prefix + 'containers/create'
- assert json.loads(args[1]['data']) == json.loads('''
- {"Tty": false, "Image": "busybox",
- "Cmd": ["ls"], "AttachStdin": false,
- "AttachStderr": true,
- "AttachStdout": true, "OpenStdin": false,
- "StdinOnce": false,
- "NetworkDisabled": false,
- "Cpuset": "0,1",
- "CpusetCpus": "0,1"}
- ''')
- assert args[1]['headers'] == {'Content-Type': 'application/json'}
-
- @requires_api_version('1.18')
def test_create_container_with_host_config_cpuset(self):
self.client.create_container(
'busybox', 'ls', host_config=self.client.create_host_config(
@@ -304,7 +267,6 @@ class CreateContainerTest(BaseAPIClientTest):
''')
assert args[1]['headers'] == {'Content-Type': 'application/json'}
- @requires_api_version('1.19')
def test_create_container_with_host_config_cpuset_mems(self):
self.client.create_container(
'busybox', 'ls', host_config=self.client.create_host_config(
@@ -374,28 +336,6 @@ class CreateContainerTest(BaseAPIClientTest):
''')
assert args[1]['headers'] == {'Content-Type': 'application/json'}
- def test_create_container_with_volumes_from(self):
- vol_names = ['foo', 'bar']
- try:
- self.client.create_container('busybox', 'true',
- volumes_from=vol_names)
- except docker.errors.DockerException:
- assert docker.utils.compare_version(
- '1.10', self.client._version
- ) >= 0
- return
-
- args = fake_request.call_args
- assert args[0][1] == url_prefix + 'containers/create'
- assert json.loads(args[1]['data'])['VolumesFrom'] == ','.join(
- vol_names
- )
- assert args[1]['headers'] == {'Content-Type': 'application/json'}
-
- def test_create_container_empty_volumes_from(self):
- with pytest.raises(docker.errors.InvalidVersion):
- self.client.create_container('busybox', 'true', volumes_from=[])
-
def test_create_named_container(self):
self.client.create_container('busybox', 'true',
name='marisa-kirisame')
diff --git a/tests/unit/api_image_test.py b/tests/unit/api_image_test.py
index 785f887..1e2315d 100644
--- a/tests/unit/api_image_test.py
+++ b/tests/unit/api_image_test.py
@@ -197,26 +197,6 @@ class ImageTest(BaseAPIClientTest):
assert excinfo.value.args[0] == 'Resource ID was not provided'
- def test_insert_image(self):
- try:
- self.client.insert(fake_api.FAKE_IMAGE_NAME,
- fake_api.FAKE_URL, fake_api.FAKE_PATH)
- except docker.errors.DeprecatedMethod:
- assert docker.utils.compare_version(
- '1.12', self.client._version
- ) >= 0
- return
-
- fake_request.assert_called_with(
- 'POST',
- url_prefix + 'images/test_image/insert',
- params={
- 'url': fake_api.FAKE_URL,
- 'path': fake_api.FAKE_PATH
- },
- timeout=DEFAULT_TIMEOUT_SECONDS
- )
-
def test_push_image(self):
with mock.patch('docker.auth.resolve_authconfig',
fake_resolve_authconfig):
diff --git a/tests/unit/api_network_test.py b/tests/unit/api_network_test.py
index fbbc97b..c78554d 100644
--- a/tests/unit/api_network_test.py
+++ b/tests/unit/api_network_test.py
@@ -3,7 +3,6 @@ import json
import six
from .api_test import BaseAPIClientTest, url_prefix, response
-from ..helpers import requires_api_version
from docker.types import IPAMConfig, IPAMPool
try:
@@ -13,7 +12,6 @@ except ImportError:
class NetworkTest(BaseAPIClientTest):
- @requires_api_version('1.21')
def test_list_networks(self):
networks = [
{
@@ -49,7 +47,6 @@ class NetworkTest(BaseAPIClientTest):
filters = json.loads(get.call_args[1]['params']['filters'])
assert filters == {'id': ['123']}
- @requires_api_version('1.21')
def test_create_network(self):
network_data = {
"id": 'abc12345',
@@ -98,7 +95,6 @@ class NetworkTest(BaseAPIClientTest):
}
}
- @requires_api_version('1.21')
def test_remove_network(self):
network_id = 'abc12345'
delete = mock.Mock(return_value=response(status_code=200))
@@ -109,7 +105,6 @@ class NetworkTest(BaseAPIClientTest):
args = delete.call_args
assert args[0][0] == url_prefix + 'networks/{0}'.format(network_id)
- @requires_api_version('1.21')
def test_inspect_network(self):
network_id = 'abc12345'
network_name = 'foo'
@@ -130,7 +125,6 @@ class NetworkTest(BaseAPIClientTest):
args = get.call_args
assert args[0][0] == url_prefix + 'networks/{0}'.format(network_id)
- @requires_api_version('1.21')
def test_connect_container_to_network(self):
network_id = 'abc12345'
container_id = 'def45678'
@@ -157,7 +151,6 @@ class NetworkTest(BaseAPIClientTest):
},
}
- @requires_api_version('1.21')
def test_disconnect_container_from_network(self):
network_id = 'abc12345'
container_id = 'def45678'
diff --git a/tests/unit/api_test.py b/tests/unit/api_test.py
index b9e0d52..c53a4be 100644
--- a/tests/unit/api_test.py
+++ b/tests/unit/api_test.py
@@ -437,7 +437,6 @@ class StreamTest(unittest.TestCase):
try:
stream = client.build(
path=self.build_context,
- stream=True
)
break
except requests.ConnectionError as e:
diff --git a/tests/unit/api_volume_test.py b/tests/unit/api_volume_test.py
index f5e5001..7850c22 100644
--- a/tests/unit/api_volume_test.py
+++ b/tests/unit/api_volume_test.py
@@ -7,7 +7,6 @@ from .api_test import BaseAPIClientTest, url_prefix, fake_request
class VolumeTest(BaseAPIClientTest):
- @requires_api_version('1.21')
def test_list_volumes(self):
volumes = self.client.volumes()
assert 'Volumes' in volumes
@@ -17,7 +16,6 @@ class VolumeTest(BaseAPIClientTest):
assert args[0][0] == 'GET'
assert args[0][1] == url_prefix + 'volumes'
- @requires_api_version('1.21')
def test_list_volumes_and_filters(self):
volumes = self.client.volumes(filters={'dangling': True})
assert 'Volumes' in volumes
@@ -29,7 +27,6 @@ class VolumeTest(BaseAPIClientTest):
assert args[1] == {'params': {'filters': '{"dangling": ["true"]}'},
'timeout': 60}
- @requires_api_version('1.21')
def test_create_volume(self):
name = 'perfectcherryblossom'
result = self.client.create_volume(name)
@@ -59,7 +56,6 @@ class VolumeTest(BaseAPIClientTest):
with pytest.raises(TypeError):
self.client.create_volume(name, labels=1)
- @requires_api_version('1.21')
def test_create_volume_with_driver(self):
name = 'perfectcherryblossom'
driver_name = 'sshfs'
@@ -72,7 +68,6 @@ class VolumeTest(BaseAPIClientTest):
assert 'Driver' in data
assert data['Driver'] == driver_name
- @requires_api_version('1.21')
def test_create_volume_invalid_opts_type(self):
with pytest.raises(TypeError):
self.client.create_volume(
@@ -99,7 +94,6 @@ class VolumeTest(BaseAPIClientTest):
assert 'Scope' in result
assert result['Scope'] == 'local'
- @requires_api_version('1.21')
def test_inspect_volume(self):
name = 'perfectcherryblossom'
result = self.client.inspect_volume(name)
@@ -112,7 +106,6 @@ class VolumeTest(BaseAPIClientTest):
assert args[0][0] == 'GET'
assert args[0][1] == '{0}volumes/{1}'.format(url_prefix, name)
- @requires_api_version('1.21')
def test_remove_volume(self):
name = 'perfectcherryblossom'
self.client.remove_volume(name)
diff --git a/tests/unit/dockertypes_test.py b/tests/unit/dockertypes_test.py
index 71dae7e..2be0578 100644
--- a/tests/unit/dockertypes_test.py
+++ b/tests/unit/dockertypes_test.py
@@ -1,14 +1,13 @@
# -*- coding: utf-8 -*-
import unittest
-import warnings
import pytest
from docker.constants import DEFAULT_DOCKER_API_VERSION
from docker.errors import InvalidArgument, InvalidVersion
from docker.types import (
- ContainerConfig, ContainerSpec, EndpointConfig, HostConfig, IPAMConfig,
+ ContainerSpec, EndpointConfig, HostConfig, IPAMConfig,
IPAMPool, LogConfig, Mount, ServiceMode, Ulimit,
)
from docker.types.services import convert_service_ports
@@ -24,33 +23,29 @@ def create_host_config(*args, **kwargs):
class HostConfigTest(unittest.TestCase):
- def test_create_host_config_no_options(self):
- config = create_host_config(version='1.19')
- assert not ('NetworkMode' in config)
-
def test_create_host_config_no_options_newer_api_version(self):
- config = create_host_config(version='1.20')
+ config = create_host_config(version='1.21')
assert config['NetworkMode'] == 'default'
def test_create_host_config_invalid_cpu_cfs_types(self):
with pytest.raises(TypeError):
- create_host_config(version='1.20', cpu_quota='0')
+ create_host_config(version='1.21', cpu_quota='0')
with pytest.raises(TypeError):
- create_host_config(version='1.20', cpu_period='0')
+ create_host_config(version='1.21', cpu_period='0')
with pytest.raises(TypeError):
- create_host_config(version='1.20', cpu_quota=23.11)
+ create_host_config(version='1.21', cpu_quota=23.11)
with pytest.raises(TypeError):
- create_host_config(version='1.20', cpu_period=1999.0)
+ create_host_config(version='1.21', cpu_period=1999.0)
def test_create_host_config_with_cpu_quota(self):
- config = create_host_config(version='1.20', cpu_quota=1999)
+ config = create_host_config(version='1.21', cpu_quota=1999)
assert config.get('CpuQuota') == 1999
def test_create_host_config_with_cpu_period(self):
- config = create_host_config(version='1.20', cpu_period=1999)
+ config = create_host_config(version='1.21', cpu_period=1999)
assert config.get('CpuPeriod') == 1999
def test_create_host_config_with_blkio_constraints(self):
@@ -79,10 +74,8 @@ class HostConfigTest(unittest.TestCase):
assert config.get('ShmSize') == 67108864
def test_create_host_config_with_oom_kill_disable(self):
- config = create_host_config(version='1.20', oom_kill_disable=True)
+ config = create_host_config(version='1.21', oom_kill_disable=True)
assert config.get('OomKillDisable') is True
- with pytest.raises(InvalidVersion):
- create_host_config(version='1.18.3', oom_kill_disable=True)
def test_create_host_config_with_userns_mode(self):
config = create_host_config(version='1.23', userns_mode='host')
@@ -109,20 +102,13 @@ class HostConfigTest(unittest.TestCase):
assert 'use-vc' in dns_opts
assert 'no-tld-query' in dns_opts
- with pytest.raises(InvalidVersion):
- create_host_config(version='1.20', dns_opt=tested_opts)
-
def test_create_host_config_with_mem_reservation(self):
config = create_host_config(version='1.21', mem_reservation=67108864)
assert config.get('MemoryReservation') == 67108864
- with pytest.raises(InvalidVersion):
- create_host_config(version='1.20', mem_reservation=67108864)
def test_create_host_config_with_kernel_memory(self):
config = create_host_config(version='1.21', kernel_memory=67108864)
assert config.get('KernelMemory') == 67108864
- with pytest.raises(InvalidVersion):
- create_host_config(version='1.20', kernel_memory=67108864)
def test_create_host_config_with_pids_limit(self):
config = create_host_config(version='1.23', pids_limit=1024)
@@ -158,9 +144,6 @@ class HostConfigTest(unittest.TestCase):
create_host_config(version='1.24', mem_swappiness='40')
def test_create_host_config_with_volume_driver(self):
- with pytest.raises(InvalidVersion):
- create_host_config(version='1.20', volume_driver='local')
-
config = create_host_config(version='1.21', volume_driver='local')
assert config.get('VolumeDriver') == 'local'
@@ -215,19 +198,6 @@ class HostConfigTest(unittest.TestCase):
create_host_config(version='1.24', cpu_rt_runtime=1000)
-class ContainerConfigTest(unittest.TestCase):
- def test_create_container_config_volume_driver_warning(self):
- with warnings.catch_warnings(record=True) as w:
- warnings.simplefilter('always')
- ContainerConfig(
- version='1.21', image='scratch', command=None,
- volume_driver='local'
- )
-
- assert len(w) == 1
- assert 'The volume_driver option has been moved' in str(w[0].message)
-
-
class ContainerSpecTest(unittest.TestCase):
def test_parse_mounts(self):
spec = ContainerSpec(
diff --git a/tests/unit/fake_api.py b/tests/unit/fake_api.py
index 37154a3..63d7331 100644
--- a/tests/unit/fake_api.py
+++ b/tests/unit/fake_api.py
@@ -21,21 +21,36 @@ FAKE_NODE_ID = '24ifsmvkjbyhk'
# for clarity and readability
-def get_fake_raw_version():
+def get_fake_version():
status_code = 200
response = {
- "ApiVersion": "1.18",
- "GitCommit": "fake-commit",
- "GoVersion": "go1.3.3",
- "Version": "1.5.0"
+ 'ApiVersion': '1.35',
+ 'Arch': 'amd64',
+ 'BuildTime': '2018-01-10T20:09:37.000000000+00:00',
+ 'Components': [{
+ 'Details': {
+ 'ApiVersion': '1.35',
+ 'Arch': 'amd64',
+ 'BuildTime': '2018-01-10T20:09:37.000000000+00:00',
+ 'Experimental': 'false',
+ 'GitCommit': '03596f5',
+ 'GoVersion': 'go1.9.2',
+ 'KernelVersion': '4.4.0-112-generic',
+ 'MinAPIVersion': '1.12',
+ 'Os': 'linux'
+ },
+ 'Name': 'Engine',
+ 'Version': '18.01.0-ce'
+ }],
+ 'GitCommit': '03596f5',
+ 'GoVersion': 'go1.9.2',
+ 'KernelVersion': '4.4.0-112-generic',
+ 'MinAPIVersion': '1.12',
+ 'Os': 'linux',
+ 'Platform': {'Name': ''},
+ 'Version': '18.01.0-ce'
}
- return status_code, response
-
-def get_fake_version():
- status_code = 200
- response = {'GoVersion': '1', 'Version': '1.1.1',
- 'GitCommit': 'deadbeef+CHANGES'}
return status_code, response
@@ -503,7 +518,7 @@ if constants.IS_WINDOWS_PLATFORM:
fake_responses = {
'{0}/version'.format(prefix):
- get_fake_raw_version,
+ get_fake_version,
'{1}/{0}/version'.format(CURRENT_VERSION, prefix):
get_fake_version,
'{1}/{0}/info'.format(CURRENT_VERSION, prefix):