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 unittest
import pytest
import six
import docker
class BaseTestCase(unittest.TestCase):
def assertIn(self, object, collection):
......@@ -14,15 +11,6 @@ class BaseTestCase(unittest.TestCase):
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):
if sys.version_info < (2, 7):
# Provide a basic implementation of addCleanup for Python < 2.7
......
......@@ -3,6 +3,8 @@ import os.path
import tarfile
import tempfile
import docker
import pytest
def make_tree(dirs, files):
......@@ -36,3 +38,12 @@ def untar_file(tardata, filename):
result = f.read()
f.close()
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
from docker import errors
from ..base import requires_api_version
from ..helpers import requires_api_version
from .base import BaseIntegrationTest
......
......@@ -8,7 +8,7 @@ from docker.utils.socket import read_exactly
import pytest
import six
from ..base import requires_api_version
from ..helpers import requires_api_version
from .. import helpers
from .base import BaseIntegrationTest, BUSYBOX
......
......@@ -5,7 +5,7 @@ from docker.utils import create_ipam_config
from docker.utils import create_ipam_pool
import pytest
from ..base import requires_api_version
from ..helpers import requires_api_version
from .base import BaseIntegrationTest
......
......@@ -2,7 +2,7 @@ import random
import docker
from ..base import requires_api_version
from ..helpers import requires_api_version
from .base import BaseIntegrationTest
......
import docker
import pytest
from ..base import requires_api_version
from ..helpers import requires_api_version
from .base import BaseIntegrationTest
......
import docker
import pytest
from .. import helpers
from ..base import requires_api_version
from ..helpers import requires_api_version
from .base import BaseIntegrationTest
......
......@@ -9,7 +9,7 @@ import pytest
import six
from . import fake_api
from ..base import requires_api_version
from ..helpers import requires_api_version
from .api_test import (
DockerClientTest, url_prefix, fake_request, DEFAULT_TIMEOUT_SECONDS,
fake_inspect_container
......
......@@ -2,7 +2,7 @@ import json
import six
from .. import base
from ..helpers import requires_api_version
from .api_test import DockerClientTest, url_prefix, response
from docker.utils import create_ipam_config, create_ipam_pool
......@@ -13,7 +13,7 @@ except ImportError:
class NetworkTest(DockerClientTest):
@base.requires_api_version('1.21')
@requires_api_version('1.21')
def test_list_networks(self):
networks = [
{
......@@ -49,7 +49,7 @@ class NetworkTest(DockerClientTest):
filters = json.loads(get.call_args[1]['params']['filters'])
self.assertEqual(filters, {'id': ['123']})
@base.requires_api_version('1.21')
@requires_api_version('1.21')
def test_create_network(self):
network_data = {
"id": 'abc12345',
......@@ -104,7 +104,7 @@ class NetworkTest(DockerClientTest):
}
})
@base.requires_api_version('1.21')
@requires_api_version('1.21')
def test_remove_network(self):
network_id = 'abc12345'
delete = mock.Mock(return_value=response(status_code=200))
......@@ -116,7 +116,7 @@ class NetworkTest(DockerClientTest):
self.assertEqual(args[0][0],
url_prefix + 'networks/{0}'.format(network_id))
@base.requires_api_version('1.21')
@requires_api_version('1.21')
def test_inspect_network(self):
network_id = 'abc12345'
network_name = 'foo'
......@@ -138,7 +138,7 @@ class NetworkTest(DockerClientTest):
self.assertEqual(args[0][0],
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):
network_id = 'abc12345'
container_id = 'def45678'
......@@ -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):
network_id = 'abc12345'
container_id = 'def45678'
......
......@@ -2,12 +2,12 @@ import json
import pytest
from .. import base
from ..helpers import requires_api_version
from .api_test import DockerClientTest, url_prefix, fake_request
class VolumeTest(DockerClientTest):
@base.requires_api_version('1.21')
@requires_api_version('1.21')
def test_list_volumes(self):
volumes = self.client.volumes()
self.assertIn('Volumes', volumes)
......@@ -17,7 +17,7 @@ class VolumeTest(DockerClientTest):
self.assertEqual(args[0][0], 'GET')
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):
volumes = self.client.volumes(filters={'dangling': True})
assert 'Volumes' in volumes
......@@ -29,7 +29,7 @@ class VolumeTest(DockerClientTest):
assert args[1] == {'params': {'filters': '{"dangling": ["true"]}'},
'timeout': 60}
@base.requires_api_version('1.21')
@requires_api_version('1.21')
def test_create_volume(self):
name = 'perfectcherryblossom'
result = self.client.create_volume(name)
......@@ -43,7 +43,7 @@ class VolumeTest(DockerClientTest):
self.assertEqual(args[0][1], url_prefix + 'volumes/create')
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):
name = 'perfectcherryblossom'
result = self.client.create_volume(name, labels={
......@@ -53,13 +53,13 @@ class VolumeTest(DockerClientTest):
{'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):
name = 'perfectcherryblossom'
with pytest.raises(TypeError):
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):
name = 'perfectcherryblossom'
driver_name = 'sshfs'
......@@ -72,7 +72,7 @@ class VolumeTest(DockerClientTest):
self.assertIn('Driver', data)
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):
with pytest.raises(TypeError):
self.client.create_volume(
......@@ -89,7 +89,7 @@ class VolumeTest(DockerClientTest):
'perfectcherryblossom', driver_opts=''
)
@base.requires_api_version('1.21')
@requires_api_version('1.21')
def test_inspect_volume(self):
name = 'perfectcherryblossom'
result = self.client.inspect_volume(name)
......@@ -102,7 +102,7 @@ class VolumeTest(DockerClientTest):
self.assertEqual(args[0][0], 'GET')
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):
name = 'perfectcherryblossom'
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