Unverified Kaydet (Commit) 69e992ec authored tarafından Ben Firshman's avatar Ben Firshman

Move requires_api_version to helpers

Because it's a helper, not a base thing. In preparation for
moving/deleting the unit test base classes.
Signed-off-by: 's avatarBen Firshman <ben@firshman.co.uk>
üst 7339d770
import sys import sys
import unittest import unittest
import pytest
import six import six
import docker
class BaseTestCase(unittest.TestCase): class BaseTestCase(unittest.TestCase):
def assertIn(self, object, collection): def assertIn(self, object, collection):
...@@ -14,15 +11,6 @@ class BaseTestCase(unittest.TestCase): ...@@ -14,15 +11,6 @@ class BaseTestCase(unittest.TestCase):
return super(BaseTestCase, self).assertIn(object, collection) return super(BaseTestCase, self).assertIn(object, collection)
def requires_api_version(version):
return pytest.mark.skipif(
docker.utils.version_lt(
docker.constants.DEFAULT_DOCKER_API_VERSION, version
),
reason="API version is too low (< {0})".format(version)
)
class Cleanup(object): class Cleanup(object):
if sys.version_info < (2, 7): if sys.version_info < (2, 7):
# Provide a basic implementation of addCleanup for Python < 2.7 # Provide a basic implementation of addCleanup for Python < 2.7
......
...@@ -3,6 +3,8 @@ import os.path ...@@ -3,6 +3,8 @@ import os.path
import tarfile import tarfile
import tempfile import tempfile
import docker
import pytest
def make_tree(dirs, files): def make_tree(dirs, files):
...@@ -36,3 +38,12 @@ def untar_file(tardata, filename): ...@@ -36,3 +38,12 @@ def untar_file(tardata, filename):
result = f.read() result = f.read()
f.close() f.close()
return result return result
def requires_api_version(version):
return pytest.mark.skipif(
docker.utils.version_lt(
docker.constants.DEFAULT_DOCKER_API_VERSION, version
),
reason="API version is too low (< {0})".format(version)
)
...@@ -8,7 +8,7 @@ import six ...@@ -8,7 +8,7 @@ import six
from docker import errors from docker import errors
from ..base import requires_api_version from ..helpers import requires_api_version
from .base import BaseIntegrationTest from .base import BaseIntegrationTest
......
...@@ -8,7 +8,7 @@ from docker.utils.socket import read_exactly ...@@ -8,7 +8,7 @@ from docker.utils.socket import read_exactly
import pytest import pytest
import six import six
from ..base import requires_api_version from ..helpers import requires_api_version
from .. import helpers from .. import helpers
from .base import BaseIntegrationTest, BUSYBOX from .base import BaseIntegrationTest, BUSYBOX
......
...@@ -5,7 +5,7 @@ from docker.utils import create_ipam_config ...@@ -5,7 +5,7 @@ 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 ..base import requires_api_version from ..helpers import requires_api_version
from .base import BaseIntegrationTest from .base import BaseIntegrationTest
......
...@@ -2,7 +2,7 @@ import random ...@@ -2,7 +2,7 @@ import random
import docker import docker
from ..base import requires_api_version from ..helpers import requires_api_version
from .base import BaseIntegrationTest from .base import BaseIntegrationTest
......
import docker import docker
import pytest import pytest
from ..base import requires_api_version from ..helpers import requires_api_version
from .base import BaseIntegrationTest from .base import BaseIntegrationTest
......
import docker import docker
import pytest import pytest
from .. import helpers from ..helpers import requires_api_version
from ..base import requires_api_version
from .base import BaseIntegrationTest from .base import BaseIntegrationTest
......
...@@ -9,7 +9,7 @@ import pytest ...@@ -9,7 +9,7 @@ import pytest
import six import six
from . import fake_api from . import fake_api
from ..base import requires_api_version from ..helpers import requires_api_version
from .api_test import ( from .api_test import (
DockerClientTest, url_prefix, fake_request, DEFAULT_TIMEOUT_SECONDS, DockerClientTest, url_prefix, fake_request, DEFAULT_TIMEOUT_SECONDS,
fake_inspect_container fake_inspect_container
......
...@@ -2,7 +2,7 @@ import json ...@@ -2,7 +2,7 @@ import json
import six import six
from .. import base from ..helpers import requires_api_version
from .api_test import DockerClientTest, url_prefix, response from .api_test import DockerClientTest, url_prefix, response
from docker.utils import create_ipam_config, create_ipam_pool from docker.utils import create_ipam_config, create_ipam_pool
...@@ -13,7 +13,7 @@ except ImportError: ...@@ -13,7 +13,7 @@ except ImportError:
class NetworkTest(DockerClientTest): class NetworkTest(DockerClientTest):
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_list_networks(self): def test_list_networks(self):
networks = [ networks = [
{ {
...@@ -49,7 +49,7 @@ class NetworkTest(DockerClientTest): ...@@ -49,7 +49,7 @@ class NetworkTest(DockerClientTest):
filters = json.loads(get.call_args[1]['params']['filters']) filters = json.loads(get.call_args[1]['params']['filters'])
self.assertEqual(filters, {'id': ['123']}) self.assertEqual(filters, {'id': ['123']})
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_create_network(self): def test_create_network(self):
network_data = { network_data = {
"id": 'abc12345', "id": 'abc12345',
...@@ -104,7 +104,7 @@ class NetworkTest(DockerClientTest): ...@@ -104,7 +104,7 @@ class NetworkTest(DockerClientTest):
} }
}) })
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_remove_network(self): def test_remove_network(self):
network_id = 'abc12345' network_id = 'abc12345'
delete = mock.Mock(return_value=response(status_code=200)) delete = mock.Mock(return_value=response(status_code=200))
...@@ -116,7 +116,7 @@ class NetworkTest(DockerClientTest): ...@@ -116,7 +116,7 @@ class NetworkTest(DockerClientTest):
self.assertEqual(args[0][0], self.assertEqual(args[0][0],
url_prefix + 'networks/{0}'.format(network_id)) url_prefix + 'networks/{0}'.format(network_id))
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_inspect_network(self): def test_inspect_network(self):
network_id = 'abc12345' network_id = 'abc12345'
network_name = 'foo' network_name = 'foo'
...@@ -138,7 +138,7 @@ class NetworkTest(DockerClientTest): ...@@ -138,7 +138,7 @@ class NetworkTest(DockerClientTest):
self.assertEqual(args[0][0], self.assertEqual(args[0][0],
url_prefix + 'networks/{0}'.format(network_id)) url_prefix + 'networks/{0}'.format(network_id))
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_connect_container_to_network(self): def test_connect_container_to_network(self):
network_id = 'abc12345' network_id = 'abc12345'
container_id = 'def45678' container_id = 'def45678'
...@@ -167,7 +167,7 @@ class NetworkTest(DockerClientTest): ...@@ -167,7 +167,7 @@ class NetworkTest(DockerClientTest):
}, },
}) })
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_disconnect_container_from_network(self): def test_disconnect_container_from_network(self):
network_id = 'abc12345' network_id = 'abc12345'
container_id = 'def45678' container_id = 'def45678'
......
...@@ -2,12 +2,12 @@ import json ...@@ -2,12 +2,12 @@ import json
import pytest import pytest
from .. import base from ..helpers import requires_api_version
from .api_test import DockerClientTest, url_prefix, fake_request from .api_test import DockerClientTest, url_prefix, fake_request
class VolumeTest(DockerClientTest): class VolumeTest(DockerClientTest):
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_list_volumes(self): def test_list_volumes(self):
volumes = self.client.volumes() volumes = self.client.volumes()
self.assertIn('Volumes', volumes) self.assertIn('Volumes', volumes)
...@@ -17,7 +17,7 @@ class VolumeTest(DockerClientTest): ...@@ -17,7 +17,7 @@ class VolumeTest(DockerClientTest):
self.assertEqual(args[0][0], 'GET') self.assertEqual(args[0][0], 'GET')
self.assertEqual(args[0][1], url_prefix + 'volumes') self.assertEqual(args[0][1], url_prefix + 'volumes')
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_list_volumes_and_filters(self): def test_list_volumes_and_filters(self):
volumes = self.client.volumes(filters={'dangling': True}) volumes = self.client.volumes(filters={'dangling': True})
assert 'Volumes' in volumes assert 'Volumes' in volumes
...@@ -29,7 +29,7 @@ class VolumeTest(DockerClientTest): ...@@ -29,7 +29,7 @@ class VolumeTest(DockerClientTest):
assert args[1] == {'params': {'filters': '{"dangling": ["true"]}'}, assert args[1] == {'params': {'filters': '{"dangling": ["true"]}'},
'timeout': 60} 'timeout': 60}
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_create_volume(self): def test_create_volume(self):
name = 'perfectcherryblossom' name = 'perfectcherryblossom'
result = self.client.create_volume(name) result = self.client.create_volume(name)
...@@ -43,7 +43,7 @@ class VolumeTest(DockerClientTest): ...@@ -43,7 +43,7 @@ class VolumeTest(DockerClientTest):
self.assertEqual(args[0][1], url_prefix + 'volumes/create') self.assertEqual(args[0][1], url_prefix + 'volumes/create')
self.assertEqual(json.loads(args[1]['data']), {'Name': name}) self.assertEqual(json.loads(args[1]['data']), {'Name': name})
@base.requires_api_version('1.23') @requires_api_version('1.23')
def test_create_volume_with_labels(self): def test_create_volume_with_labels(self):
name = 'perfectcherryblossom' name = 'perfectcherryblossom'
result = self.client.create_volume(name, labels={ result = self.client.create_volume(name, labels={
...@@ -53,13 +53,13 @@ class VolumeTest(DockerClientTest): ...@@ -53,13 +53,13 @@ class VolumeTest(DockerClientTest):
{'com.example.some-label': 'some-value'} {'com.example.some-label': 'some-value'}
) )
@base.requires_api_version('1.23') @requires_api_version('1.23')
def test_create_volume_with_invalid_labels(self): def test_create_volume_with_invalid_labels(self):
name = 'perfectcherryblossom' name = 'perfectcherryblossom'
with pytest.raises(TypeError): with pytest.raises(TypeError):
self.client.create_volume(name, labels=1) self.client.create_volume(name, labels=1)
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_create_volume_with_driver(self): def test_create_volume_with_driver(self):
name = 'perfectcherryblossom' name = 'perfectcherryblossom'
driver_name = 'sshfs' driver_name = 'sshfs'
...@@ -72,7 +72,7 @@ class VolumeTest(DockerClientTest): ...@@ -72,7 +72,7 @@ class VolumeTest(DockerClientTest):
self.assertIn('Driver', data) self.assertIn('Driver', data)
self.assertEqual(data['Driver'], driver_name) self.assertEqual(data['Driver'], driver_name)
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_create_volume_invalid_opts_type(self): def test_create_volume_invalid_opts_type(self):
with pytest.raises(TypeError): with pytest.raises(TypeError):
self.client.create_volume( self.client.create_volume(
...@@ -89,7 +89,7 @@ class VolumeTest(DockerClientTest): ...@@ -89,7 +89,7 @@ class VolumeTest(DockerClientTest):
'perfectcherryblossom', driver_opts='' 'perfectcherryblossom', driver_opts=''
) )
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_inspect_volume(self): def test_inspect_volume(self):
name = 'perfectcherryblossom' name = 'perfectcherryblossom'
result = self.client.inspect_volume(name) result = self.client.inspect_volume(name)
...@@ -102,7 +102,7 @@ class VolumeTest(DockerClientTest): ...@@ -102,7 +102,7 @@ class VolumeTest(DockerClientTest):
self.assertEqual(args[0][0], 'GET') self.assertEqual(args[0][0], 'GET')
self.assertEqual(args[0][1], '{0}volumes/{1}'.format(url_prefix, name)) self.assertEqual(args[0][1], '{0}volumes/{1}'.format(url_prefix, name))
@base.requires_api_version('1.21') @requires_api_version('1.21')
def test_remove_volume(self): def test_remove_volume(self):
name = 'perfectcherryblossom' name = 'perfectcherryblossom'
self.client.remove_volume(name) self.client.remove_volume(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