mirror of https://github.com/docker/docker-py.git
Flake8 compliance + flake8 tests in tox.ini
This commit is contained in:
parent
86b341ddf9
commit
acd2607407
|
@ -12,4 +12,4 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from .client import Client, APIError
|
from .client import Client, APIError # flake8: noqa
|
||||||
|
|
|
@ -1 +1,9 @@
|
||||||
from .auth import *
|
|
||||||
|
|
||||||
|
from .auth import (
|
||||||
|
INDEX_URL,
|
||||||
|
encode_header,
|
||||||
|
load_config,
|
||||||
|
resolve_authconfig,
|
||||||
|
resolve_repository_name
|
||||||
|
) # flake8: noqa
|
|
@ -31,7 +31,7 @@ class APIError(requests.exceptions.HTTPError):
|
||||||
|
|
||||||
self.explanation = explanation
|
self.explanation = explanation
|
||||||
|
|
||||||
if self.explanation is None and response.content and len(response.content) > 0:
|
if self.explanation is None and response.content:
|
||||||
self.explanation = response.content.strip()
|
self.explanation = response.content.strip()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -86,13 +86,15 @@ class Client(requests.Session):
|
||||||
return response.text
|
return response.text
|
||||||
|
|
||||||
def _container_config(self, image, command, hostname=None, user=None,
|
def _container_config(self, image, command, hostname=None, user=None,
|
||||||
detach=False, stdin_open=False, tty=False, mem_limit=0, ports=None,
|
detach=False, stdin_open=False, tty=False,
|
||||||
environment=None, dns=None, volumes=None, volumes_from=None,
|
mem_limit=0, ports=None, environment=None, dns=None,
|
||||||
privileged=False):
|
volumes=None, volumes_from=None, privileged=False):
|
||||||
if isinstance(command, six.string_types):
|
if isinstance(command, six.string_types):
|
||||||
command = shlex.split(str(command))
|
command = shlex.split(str(command))
|
||||||
if isinstance(environment, dict):
|
if isinstance(environment, dict):
|
||||||
environment = ['{0}={1}'.format(k, v) for k, v in environment.items()]
|
environment = [
|
||||||
|
'{0}={1}'.format(k, v) for k, v in environment.items()
|
||||||
|
]
|
||||||
|
|
||||||
attach_stdin = False
|
attach_stdin = False
|
||||||
attach_stdout = False
|
attach_stdout = False
|
||||||
|
@ -166,21 +168,27 @@ class Client(requests.Session):
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
def build(self, path=None, tag=None, quiet=False, fileobj=None, nocache=False, rm=False):
|
def build(self, path=None, tag=None, quiet=False, fileobj=None,
|
||||||
|
nocache=False, rm=False):
|
||||||
remote = context = headers = None
|
remote = context = headers = None
|
||||||
if path is None and fileobj is None:
|
if path is None and fileobj is None:
|
||||||
raise Exception("Either path or fileobj needs to be provided.")
|
raise Exception("Either path or fileobj needs to be provided.")
|
||||||
|
|
||||||
if fileobj is not None:
|
if fileobj is not None:
|
||||||
context = utils.mkbuildcontext(fileobj)
|
context = utils.mkbuildcontext(fileobj)
|
||||||
elif (path.startswith('http://') or path.startswith('https://') or
|
elif path.startswith(('http://', 'https://', 'git://', 'github.com/')):
|
||||||
path.startswith('git://') or path.startswith('github.com/')):
|
|
||||||
remote = path
|
remote = path
|
||||||
else:
|
else:
|
||||||
context = utils.tar(path)
|
context = utils.tar(path)
|
||||||
|
|
||||||
u = self._url('/build')
|
u = self._url('/build')
|
||||||
params = { 't': tag, 'remote': remote, 'q': quiet, 'nocache': nocache, 'rm': rm }
|
params = {
|
||||||
|
't': tag,
|
||||||
|
'remote': remote,
|
||||||
|
'q': quiet,
|
||||||
|
'nocache': nocache,
|
||||||
|
'rm': rm
|
||||||
|
}
|
||||||
if context is not None:
|
if context is not None:
|
||||||
headers = {'Content-Type': 'application/tar'}
|
headers = {'Content-Type': 'application/tar'}
|
||||||
res = self._result(self.post(u, context, params=params,
|
res = self._result(self.post(u, context, params=params,
|
||||||
|
@ -221,21 +229,23 @@ class Client(requests.Session):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def copy(self, container, resource):
|
def copy(self, container, resource):
|
||||||
res = self._post_json(self._url("/containers/{0}/copy".format(container)),
|
res = self._post_json(
|
||||||
|
self._url("/containers/{0}/copy".format(container)),
|
||||||
{"Resource": resource},
|
{"Resource": resource},
|
||||||
stream=True)
|
stream=True
|
||||||
|
)
|
||||||
self._raise_for_status(res)
|
self._raise_for_status(res)
|
||||||
return res.raw
|
return res.raw
|
||||||
|
|
||||||
def create_container(self, image, command, hostname=None, user=None,
|
def create_container(self, image, command, hostname=None, user=None,
|
||||||
detach=False, stdin_open=False, tty=False, mem_limit=0, ports=None,
|
detach=False, stdin_open=False, tty=False,
|
||||||
environment=None, dns=None, volumes=None, volumes_from=None,
|
mem_limit=0, ports=None, environment=None, dns=None,
|
||||||
privileged=False):
|
volumes=None, volumes_from=None, privileged=False):
|
||||||
|
|
||||||
|
config = self._container_config(
|
||||||
config = self._container_config(image, command, hostname, user,
|
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
|
||||||
detach, stdin_open, tty, mem_limit, ports, environment, dns,
|
ports, environment, dns, volumes, volumes_from, privileged
|
||||||
volumes, volumes_from, privileged)
|
)
|
||||||
return self.create_container_from_config(config)
|
return self.create_container_from_config(config)
|
||||||
|
|
||||||
def create_container_from_config(self, config):
|
def create_container_from_config(self, config):
|
||||||
|
@ -312,12 +322,14 @@ class Client(requests.Session):
|
||||||
def inspect_container(self, container):
|
def inspect_container(self, container):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
container = container.get('Id')
|
container = container.get('Id')
|
||||||
return self._result(self.get(self._url("/containers/{0}/json".
|
return self._result(self.get(
|
||||||
format(container))), True)
|
self._url("/containers/{0}/json".format(container))
|
||||||
|
), True)
|
||||||
|
|
||||||
def inspect_image(self, image_id):
|
def inspect_image(self, image_id):
|
||||||
return self._result(self.get(self._url("/images/{0}/json".
|
return self._result(self.get(
|
||||||
format(image_id))), True)
|
self._url("/images/{0}/json".format(image_id))
|
||||||
|
), True)
|
||||||
|
|
||||||
def kill(self, container):
|
def kill(self, container):
|
||||||
if isinstance(container, dict):
|
if isinstance(container, dict):
|
||||||
|
@ -438,7 +450,9 @@ class Client(requests.Session):
|
||||||
'LxcConf': lxc_conf
|
'LxcConf': lxc_conf
|
||||||
}
|
}
|
||||||
if binds:
|
if binds:
|
||||||
bind_pairs = ['{0}:{1}'.format(host, dest) for host, dest in binds.items()]
|
bind_pairs = [
|
||||||
|
'{0}:{1}'.format(host, dest) for host, dest in binds.items()
|
||||||
|
]
|
||||||
start_config['Binds'] = bind_pairs
|
start_config['Binds'] = bind_pairs
|
||||||
|
|
||||||
url = self._url("/containers/{0}/start".format(container))
|
url = self._url("/containers/{0}/start".format(container))
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
from .unixconn import UnixAdapter
|
from .unixconn import UnixAdapter # flake8: noqa
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
from .utils import mkbuildcontext, tar, compare_version
|
from .utils import mkbuildcontext, tar, compare_version # flake8: noqa
|
||||||
|
|
|
@ -1,4 +1,16 @@
|
||||||
import json
|
# Copyright 2013 dotCloud inc.
|
||||||
|
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
CURRENT_VERSION = 'v1.4'
|
CURRENT_VERSION = 'v1.4'
|
||||||
|
|
||||||
|
@ -30,21 +42,24 @@ def get_fake_search():
|
||||||
|
|
||||||
def get_fake_images():
|
def get_fake_images():
|
||||||
status_code = 200
|
status_code = 200
|
||||||
response = [
|
response = [{
|
||||||
{'Id': FAKE_IMAGE_ID, 'Created': '2 days ago', 'Repository': 'busybox', 'Tag': 'latest'}
|
'Id': FAKE_IMAGE_ID,
|
||||||
]
|
'Created': '2 days ago',
|
||||||
|
'Repository': 'busybox',
|
||||||
|
'Tag': 'latest'
|
||||||
|
}]
|
||||||
return status_code, response
|
return status_code, response
|
||||||
|
|
||||||
|
|
||||||
def get_fake_containers():
|
def get_fake_containers():
|
||||||
status_code = 200
|
status_code = 200
|
||||||
response = [
|
response = [{
|
||||||
{'Id': FAKE_CONTAINER_ID,
|
'Id': FAKE_CONTAINER_ID,
|
||||||
'Image': 'busybox:latest',
|
'Image': 'busybox:latest',
|
||||||
'Created': '2 days ago',
|
'Created': '2 days ago',
|
||||||
'Command': 'true',
|
'Command': 'true',
|
||||||
'Status': 'fake status'}
|
'Status': 'fake status'
|
||||||
]
|
}]
|
||||||
return status_code, response
|
return status_code, response
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,24 +160,44 @@ def post_fake_build_container():
|
||||||
|
|
||||||
|
|
||||||
## maps real api url to fake response callback
|
## maps real api url to fake response callback
|
||||||
|
prefix = 'unix://var/run/docker.sock'
|
||||||
fake_responses = {
|
fake_responses = {
|
||||||
'unix://var/run/docker.sock/{0}/version'.format(CURRENT_VERSION): get_fake_version,
|
'{1}/{0}/version'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/info'.format(CURRENT_VERSION): get_fake_info,
|
get_fake_version,
|
||||||
'unix://var/run/docker.sock/{0}/images/search'.format(CURRENT_VERSION): get_fake_search,
|
'{1}/{0}/info'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/images/json'.format(CURRENT_VERSION): get_fake_images,
|
get_fake_info,
|
||||||
'unix://var/run/docker.sock/{0}/containers/ps'.format(CURRENT_VERSION): get_fake_containers,
|
'{1}/{0}/images/search'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/start'.format(CURRENT_VERSION): post_fake_start_container,
|
get_fake_search,
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION): get_fake_inspect_container,
|
'{1}/{0}/images/json'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/wait'.format(CURRENT_VERSION): get_fake_wait,
|
get_fake_images,
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/attach'.format(CURRENT_VERSION): get_fake_logs,
|
'{1}/{0}/containers/ps'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/changes'.format(CURRENT_VERSION): get_fake_diff,
|
get_fake_containers,
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/stop'.format(CURRENT_VERSION): post_fake_stop_container,
|
'{1}/{0}/containers/3cc2351ab11b/start'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/kill'.format(CURRENT_VERSION): post_fake_kill_container,
|
post_fake_start_container,
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b/restart'.format(CURRENT_VERSION): post_fake_restart_container,
|
'{1}/{0}/containers/3cc2351ab11b/json'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/containers/3cc2351ab11b'.format(CURRENT_VERSION): delete_fake_remove_container,
|
get_fake_inspect_container,
|
||||||
'unix://var/run/docker.sock/{0}/images/create'.format(CURRENT_VERSION): post_fake_image_create,
|
'{1}/{0}/containers/3cc2351ab11b/wait'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/images/e9aa60c60128'.format(CURRENT_VERSION): delete_fake_remove_image,
|
get_fake_wait,
|
||||||
'unix://var/run/docker.sock/{0}/commit'.format(CURRENT_VERSION): post_fake_commit,
|
'{1}/{0}/containers/3cc2351ab11b/attach'.format(CURRENT_VERSION, prefix):
|
||||||
'unix://var/run/docker.sock/{0}/containers/create'.format(CURRENT_VERSION): post_fake_create_container,
|
get_fake_logs,
|
||||||
'unix://var/run/docker.sock/{0}/build'.format(CURRENT_VERSION): post_fake_build_container
|
'{1}/{0}/containers/3cc2351ab11b/changes'.format(CURRENT_VERSION, prefix):
|
||||||
|
get_fake_diff,
|
||||||
|
'{1}/{0}/containers/3cc2351ab11b/stop'.format(CURRENT_VERSION, prefix):
|
||||||
|
post_fake_stop_container,
|
||||||
|
'{1}/{0}/containers/3cc2351ab11b/kill'.format(CURRENT_VERSION, prefix):
|
||||||
|
post_fake_kill_container,
|
||||||
|
'{1}/{0}/containers/3cc2351ab11b/restart'.format(CURRENT_VERSION, prefix):
|
||||||
|
post_fake_restart_container,
|
||||||
|
'{1}/{0}/containers/3cc2351ab11b'.format(CURRENT_VERSION, prefix):
|
||||||
|
delete_fake_remove_container,
|
||||||
|
'{1}/{0}/images/create'.format(CURRENT_VERSION, prefix):
|
||||||
|
post_fake_image_create,
|
||||||
|
'{1}/{0}/images/e9aa60c60128'.format(CURRENT_VERSION, prefix):
|
||||||
|
delete_fake_remove_image,
|
||||||
|
'{1}/{0}/commit'.format(CURRENT_VERSION, prefix):
|
||||||
|
post_fake_commit,
|
||||||
|
'{1}/{0}/containers/create'.format(CURRENT_VERSION, prefix):
|
||||||
|
post_fake_create_container,
|
||||||
|
'{1}/{0}/build'.format(CURRENT_VERSION, prefix):
|
||||||
|
post_fake_build_container
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import os
|
|
||||||
import io
|
import io
|
||||||
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
@ -52,6 +52,7 @@ class BaseTestCase(unittest.TestCase):
|
||||||
## INFORMATION TESTS ##
|
## INFORMATION TESTS ##
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
|
|
||||||
class TestVersion(BaseTestCase):
|
class TestVersion(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.version()
|
res = self.client.version()
|
||||||
|
@ -59,6 +60,7 @@ class TestVersion(BaseTestCase):
|
||||||
self.assertIn('Version', res)
|
self.assertIn('Version', res)
|
||||||
self.assertEqual(len(res['Version'].split('.')), 3)
|
self.assertEqual(len(res['Version'].split('.')), 3)
|
||||||
|
|
||||||
|
|
||||||
class TestInfo(BaseTestCase):
|
class TestInfo(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.info()
|
res = self.client.info()
|
||||||
|
@ -66,6 +68,7 @@ class TestInfo(BaseTestCase):
|
||||||
self.assertIn('Images', res)
|
self.assertIn('Images', res)
|
||||||
self.assertIn('Debug', res)
|
self.assertIn('Debug', res)
|
||||||
|
|
||||||
|
|
||||||
class TestSearch(BaseTestCase):
|
class TestSearch(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.search('busybox')
|
res = self.client.search('busybox')
|
||||||
|
@ -78,6 +81,7 @@ class TestSearch(BaseTestCase):
|
||||||
## LISTING TESTS ##
|
## LISTING TESTS ##
|
||||||
###################
|
###################
|
||||||
|
|
||||||
|
|
||||||
class TestImages(BaseTestCase):
|
class TestImages(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res1 = self.client.images(all=True)
|
res1 = self.client.images(all=True)
|
||||||
|
@ -94,11 +98,13 @@ class TestImages(BaseTestCase):
|
||||||
distinct.append(img['Id'])
|
distinct.append(img['Id'])
|
||||||
self.assertEqual(len(distinct), self.client.info()['Images'])
|
self.assertEqual(len(distinct), self.client.info()['Images'])
|
||||||
|
|
||||||
|
|
||||||
class TestImageIds(BaseTestCase):
|
class TestImageIds(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res1 = self.client.images(quiet=True)
|
res1 = self.client.images(quiet=True)
|
||||||
self.assertEqual(type(res1[0]), six.text_type)
|
self.assertEqual(type(res1[0]), six.text_type)
|
||||||
|
|
||||||
|
|
||||||
class TestListContainers(BaseTestCase):
|
class TestListContainers(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res0 = self.client.containers(all=True)
|
res0 = self.client.containers(all=True)
|
||||||
|
@ -122,12 +128,14 @@ class TestListContainers(BaseTestCase):
|
||||||
## CONTAINER TESTS ##
|
## CONTAINER TESTS ##
|
||||||
#####################
|
#####################
|
||||||
|
|
||||||
|
|
||||||
class TestCreateContainer(BaseTestCase):
|
class TestCreateContainer(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.create_container('busybox', 'true')
|
res = self.client.create_container('busybox', 'true')
|
||||||
self.assertIn('Id', res)
|
self.assertIn('Id', res)
|
||||||
self.tmp_containers.append(res['Id'])
|
self.tmp_containers.append(res['Id'])
|
||||||
|
|
||||||
|
|
||||||
class TestCreateContainerWithBinds(BaseTestCase):
|
class TestCreateContainerWithBinds(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
mount_dest = '/mnt'
|
mount_dest = '/mnt'
|
||||||
|
@ -137,8 +145,10 @@ class TestCreateContainerWithBinds(BaseTestCase):
|
||||||
shared_file = os.path.join(mount_origin, filename)
|
shared_file = os.path.join(mount_origin, filename)
|
||||||
|
|
||||||
with open(shared_file, 'w'):
|
with open(shared_file, 'w'):
|
||||||
container = self.client.create_container('busybox',
|
container = self.client.create_container(
|
||||||
['ls', mount_dest], volumes={mount_dest: {}})
|
'busybox',
|
||||||
|
['ls', mount_dest], volumes={mount_dest: {}}
|
||||||
|
)
|
||||||
container_id = container['Id']
|
container_id = container['Id']
|
||||||
self.client.start(container_id, binds={mount_origin: mount_dest})
|
self.client.start(container_id, binds={mount_origin: mount_dest})
|
||||||
self.tmp_containers.append(container_id)
|
self.tmp_containers.append(container_id)
|
||||||
|
@ -149,6 +159,7 @@ class TestCreateContainerWithBinds(BaseTestCase):
|
||||||
os.unlink(shared_file)
|
os.unlink(shared_file)
|
||||||
self.assertIn(filename, logs)
|
self.assertIn(filename, logs)
|
||||||
|
|
||||||
|
|
||||||
class TestCreateContainerPrivileged(BaseTestCase):
|
class TestCreateContainerPrivileged(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.create_container('busybox', 'true', privileged=True)
|
res = self.client.create_container('busybox', 'true', privileged=True)
|
||||||
|
@ -156,6 +167,7 @@ class TestCreateContainerPrivileged(BaseTestCase):
|
||||||
self.assertIn('Config', inspect)
|
self.assertIn('Config', inspect)
|
||||||
self.assertEqual(inspect['Config']['Privileged'], True)
|
self.assertEqual(inspect['Config']['Privileged'], True)
|
||||||
|
|
||||||
|
|
||||||
class TestStartContainer(BaseTestCase):
|
class TestStartContainer(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.create_container('busybox', 'true')
|
res = self.client.create_container('busybox', 'true')
|
||||||
|
@ -173,6 +185,7 @@ class TestStartContainer(BaseTestCase):
|
||||||
self.assertIn('ExitCode', inspect['State'])
|
self.assertIn('ExitCode', inspect['State'])
|
||||||
self.assertEqual(inspect['State']['ExitCode'], 0)
|
self.assertEqual(inspect['State']['ExitCode'], 0)
|
||||||
|
|
||||||
|
|
||||||
class TestStartContainerWithDictInsteadOfId(BaseTestCase):
|
class TestStartContainerWithDictInsteadOfId(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.create_container('busybox', 'true')
|
res = self.client.create_container('busybox', 'true')
|
||||||
|
@ -190,6 +203,7 @@ class TestStartContainerWithDictInsteadOfId(BaseTestCase):
|
||||||
self.assertIn('ExitCode', inspect['State'])
|
self.assertIn('ExitCode', inspect['State'])
|
||||||
self.assertEqual(inspect['State']['ExitCode'], 0)
|
self.assertEqual(inspect['State']['ExitCode'], 0)
|
||||||
|
|
||||||
|
|
||||||
class TestWait(BaseTestCase):
|
class TestWait(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.create_container('busybox', ['sleep', '10'])
|
res = self.client.create_container('busybox', ['sleep', '10'])
|
||||||
|
@ -204,6 +218,7 @@ class TestWait(BaseTestCase):
|
||||||
self.assertIn('ExitCode', inspect['State'])
|
self.assertIn('ExitCode', inspect['State'])
|
||||||
self.assertEqual(inspect['State']['ExitCode'], exitcode)
|
self.assertEqual(inspect['State']['ExitCode'], exitcode)
|
||||||
|
|
||||||
|
|
||||||
class TestWaitWithDictInsteadOfId(BaseTestCase):
|
class TestWaitWithDictInsteadOfId(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
res = self.client.create_container('busybox', ['sleep', '10'])
|
res = self.client.create_container('busybox', ['sleep', '10'])
|
||||||
|
@ -218,11 +233,13 @@ class TestWaitWithDictInsteadOfId(BaseTestCase):
|
||||||
self.assertIn('ExitCode', inspect['State'])
|
self.assertIn('ExitCode', inspect['State'])
|
||||||
self.assertEqual(inspect['State']['ExitCode'], exitcode)
|
self.assertEqual(inspect['State']['ExitCode'], exitcode)
|
||||||
|
|
||||||
|
|
||||||
class TestLogs(BaseTestCase):
|
class TestLogs(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
snippet = 'Flowering Nights (Sakuya Iyazoi)'
|
snippet = 'Flowering Nights (Sakuya Iyazoi)'
|
||||||
container = self.client.create_container('busybox',
|
container = self.client.create_container(
|
||||||
'echo {0}'.format(snippet))
|
'busybox', 'echo {0}'.format(snippet)
|
||||||
|
)
|
||||||
id = container['Id']
|
id = container['Id']
|
||||||
self.client.start(id)
|
self.client.start(id)
|
||||||
self.tmp_containers.append(id)
|
self.tmp_containers.append(id)
|
||||||
|
@ -231,11 +248,13 @@ class TestLogs(BaseTestCase):
|
||||||
logs = self.client.logs(id)
|
logs = self.client.logs(id)
|
||||||
self.assertEqual(logs, snippet + '\n')
|
self.assertEqual(logs, snippet + '\n')
|
||||||
|
|
||||||
|
|
||||||
class TestLogsWithDictInsteadOfId(BaseTestCase):
|
class TestLogsWithDictInsteadOfId(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
snippet = 'Flowering Nights (Sakuya Iyazoi)'
|
snippet = 'Flowering Nights (Sakuya Iyazoi)'
|
||||||
container = self.client.create_container('busybox',
|
container = self.client.create_container(
|
||||||
'echo {0}'.format(snippet))
|
'busybox', 'echo {0}'.format(snippet)
|
||||||
|
)
|
||||||
id = container['Id']
|
id = container['Id']
|
||||||
self.client.start(id)
|
self.client.start(id)
|
||||||
self.tmp_containers.append(id)
|
self.tmp_containers.append(id)
|
||||||
|
@ -244,6 +263,7 @@ class TestLogsWithDictInsteadOfId(BaseTestCase):
|
||||||
logs = self.client.logs(container)
|
logs = self.client.logs(container)
|
||||||
self.assertEqual(logs, snippet + '\n')
|
self.assertEqual(logs, snippet + '\n')
|
||||||
|
|
||||||
|
|
||||||
class TestDiff(BaseTestCase):
|
class TestDiff(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['touch', '/test'])
|
container = self.client.create_container('busybox', ['touch', '/test'])
|
||||||
|
@ -258,6 +278,7 @@ class TestDiff(BaseTestCase):
|
||||||
self.assertIn('Kind', test_diff[0])
|
self.assertIn('Kind', test_diff[0])
|
||||||
self.assertEqual(test_diff[0]['Kind'], 1)
|
self.assertEqual(test_diff[0]['Kind'], 1)
|
||||||
|
|
||||||
|
|
||||||
class TestDiffWithDictInsteadOfId(BaseTestCase):
|
class TestDiffWithDictInsteadOfId(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['touch', '/test'])
|
container = self.client.create_container('busybox', ['touch', '/test'])
|
||||||
|
@ -272,6 +293,7 @@ class TestDiffWithDictInsteadOfId(BaseTestCase):
|
||||||
self.assertIn('Kind', test_diff[0])
|
self.assertIn('Kind', test_diff[0])
|
||||||
self.assertEqual(test_diff[0]['Kind'], 1)
|
self.assertEqual(test_diff[0]['Kind'], 1)
|
||||||
|
|
||||||
|
|
||||||
class TestStop(BaseTestCase):
|
class TestStop(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['sleep', '9999'])
|
container = self.client.create_container('busybox', ['sleep', '9999'])
|
||||||
|
@ -287,6 +309,7 @@ class TestStop(BaseTestCase):
|
||||||
self.assertIn('Running', state)
|
self.assertIn('Running', state)
|
||||||
self.assertEqual(state['Running'], False)
|
self.assertEqual(state['Running'], False)
|
||||||
|
|
||||||
|
|
||||||
class TestStopWithDictInsteadOfId(BaseTestCase):
|
class TestStopWithDictInsteadOfId(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['sleep', '9999'])
|
container = self.client.create_container('busybox', ['sleep', '9999'])
|
||||||
|
@ -303,6 +326,7 @@ class TestStopWithDictInsteadOfId(BaseTestCase):
|
||||||
self.assertIn('Running', state)
|
self.assertIn('Running', state)
|
||||||
self.assertEqual(state['Running'], False)
|
self.assertEqual(state['Running'], False)
|
||||||
|
|
||||||
|
|
||||||
class TestKill(BaseTestCase):
|
class TestKill(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['sleep', '9999'])
|
container = self.client.create_container('busybox', ['sleep', '9999'])
|
||||||
|
@ -318,6 +342,7 @@ class TestKill(BaseTestCase):
|
||||||
self.assertIn('Running', state)
|
self.assertIn('Running', state)
|
||||||
self.assertEqual(state['Running'], False)
|
self.assertEqual(state['Running'], False)
|
||||||
|
|
||||||
|
|
||||||
class TestKillWithDictInsteadOfId(BaseTestCase):
|
class TestKillWithDictInsteadOfId(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['sleep', '9999'])
|
container = self.client.create_container('busybox', ['sleep', '9999'])
|
||||||
|
@ -333,6 +358,7 @@ class TestKillWithDictInsteadOfId(BaseTestCase):
|
||||||
self.assertIn('Running', state)
|
self.assertIn('Running', state)
|
||||||
self.assertEqual(state['Running'], False)
|
self.assertEqual(state['Running'], False)
|
||||||
|
|
||||||
|
|
||||||
class TestRestart(BaseTestCase):
|
class TestRestart(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['sleep', '9999'])
|
container = self.client.create_container('busybox', ['sleep', '9999'])
|
||||||
|
@ -353,6 +379,7 @@ class TestRestart(BaseTestCase):
|
||||||
self.assertEqual(info2['State']['Running'], True)
|
self.assertEqual(info2['State']['Running'], True)
|
||||||
self.client.kill(id)
|
self.client.kill(id)
|
||||||
|
|
||||||
|
|
||||||
class TestRestartWithDictInsteadOfId(BaseTestCase):
|
class TestRestartWithDictInsteadOfId(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['sleep', '9999'])
|
container = self.client.create_container('busybox', ['sleep', '9999'])
|
||||||
|
@ -374,6 +401,7 @@ class TestRestartWithDictInsteadOfId(BaseTestCase):
|
||||||
self.assertEqual(info2['State']['Running'], True)
|
self.assertEqual(info2['State']['Running'], True)
|
||||||
self.client.kill(id)
|
self.client.kill(id)
|
||||||
|
|
||||||
|
|
||||||
class TestRemoveContainer(BaseTestCase):
|
class TestRemoveContainer(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['true'])
|
container = self.client.create_container('busybox', ['true'])
|
||||||
|
@ -385,6 +413,7 @@ class TestRemoveContainer(BaseTestCase):
|
||||||
res = [x for x in containers if 'Id' in x and x['Id'].startswith(id)]
|
res = [x for x in containers if 'Id' in x and x['Id'].startswith(id)]
|
||||||
self.assertEqual(len(res), 0)
|
self.assertEqual(len(res), 0)
|
||||||
|
|
||||||
|
|
||||||
class TestRemoveContainerWithDictInsteadOfId(BaseTestCase):
|
class TestRemoveContainerWithDictInsteadOfId(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['true'])
|
container = self.client.create_container('busybox', ['true'])
|
||||||
|
@ -400,6 +429,7 @@ class TestRemoveContainerWithDictInsteadOfId(BaseTestCase):
|
||||||
## IMAGES TESTS ##
|
## IMAGES TESTS ##
|
||||||
##################
|
##################
|
||||||
|
|
||||||
|
|
||||||
class TestPull(BaseTestCase):
|
class TestPull(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
try:
|
try:
|
||||||
|
@ -418,6 +448,7 @@ class TestPull(BaseTestCase):
|
||||||
self.tmp_imgs.append('joffrey/test001')
|
self.tmp_imgs.append('joffrey/test001')
|
||||||
self.tmp_imgs.append('376968a23351')
|
self.tmp_imgs.append('376968a23351')
|
||||||
|
|
||||||
|
|
||||||
class TestCommit(BaseTestCase):
|
class TestCommit(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
container = self.client.create_container('busybox', ['touch', '/test'])
|
container = self.client.create_container('busybox', ['touch', '/test'])
|
||||||
|
@ -458,6 +489,7 @@ class TestRemoveImage(BaseTestCase):
|
||||||
# BUILDER TESTS #
|
# BUILDER TESTS #
|
||||||
#################
|
#################
|
||||||
|
|
||||||
|
|
||||||
class TestBuild(BaseTestCase):
|
class TestBuild(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
script = io.BytesIO('\n'.join([
|
script = io.BytesIO('\n'.join([
|
||||||
|
@ -465,7 +497,8 @@ class TestBuild(BaseTestCase):
|
||||||
'MAINTAINER docker-py',
|
'MAINTAINER docker-py',
|
||||||
'RUN mkdir -p /tmp/test',
|
'RUN mkdir -p /tmp/test',
|
||||||
'EXPOSE 8080',
|
'EXPOSE 8080',
|
||||||
'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz /tmp/silence.tar.gz'
|
'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz'
|
||||||
|
' /tmp/silence.tar.gz'
|
||||||
]).encode('ascii'))
|
]).encode('ascii'))
|
||||||
img, logs = self.client.build(fileobj=script)
|
img, logs = self.client.build(fileobj=script)
|
||||||
self.assertNotEqual(img, None)
|
self.assertNotEqual(img, None)
|
||||||
|
@ -495,7 +528,8 @@ class TestBuildFromStringIO(BaseTestCase):
|
||||||
'MAINTAINER docker-py',
|
'MAINTAINER docker-py',
|
||||||
'RUN mkdir -p /tmp/test',
|
'RUN mkdir -p /tmp/test',
|
||||||
'EXPOSE 8080',
|
'EXPOSE 8080',
|
||||||
'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz /tmp/silence.tar.gz'
|
'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz'
|
||||||
|
' /tmp/silence.tar.gz'
|
||||||
]))
|
]))
|
||||||
img, logs = self.client.build(fileobj=script)
|
img, logs = self.client.build(fileobj=script)
|
||||||
self.assertNotEqual(img, None)
|
self.assertNotEqual(img, None)
|
||||||
|
@ -519,12 +553,15 @@ class TestBuildFromStringIO(BaseTestCase):
|
||||||
## PY SPECIFIC TESTS ##
|
## PY SPECIFIC TESTS ##
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
|
|
||||||
class TestRunShlex(BaseTestCase):
|
class TestRunShlex(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
commands = [
|
commands = [
|
||||||
'true',
|
'true',
|
||||||
'echo "The Young Descendant of Tepes & Septette for the Dead Princess"',
|
'echo "The Young Descendant of Tepes & Septette for the '
|
||||||
'echo -n "The Young Descendant of Tepes & Septette for the Dead Princess"',
|
'Dead Princess"',
|
||||||
|
'echo -n "The Young Descendant of Tepes & Septette for the '
|
||||||
|
'Dead Princess"',
|
||||||
'/bin/sh -c "echo Hello World"',
|
'/bin/sh -c "echo Hello World"',
|
||||||
'/bin/sh -c \'echo "Hello World"\'',
|
'/bin/sh -c \'echo "Hello World"\'',
|
||||||
'echo "\"Night of Nights\""',
|
'echo "\"Night of Nights\""',
|
||||||
|
@ -538,6 +575,7 @@ class TestRunShlex(BaseTestCase):
|
||||||
exitcode = self.client.wait(id)
|
exitcode = self.client.wait(id)
|
||||||
self.assertEqual(exitcode, 0, msg=cmd)
|
self.assertEqual(exitcode, 0, msg=cmd)
|
||||||
|
|
||||||
|
|
||||||
class TestLoadConfig(BaseTestCase):
|
class TestLoadConfig(BaseTestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
folder = tempfile.mkdtemp()
|
folder = tempfile.mkdtemp()
|
||||||
|
|
|
@ -60,7 +60,8 @@ def fake_resp(url, data=None, **kwargs):
|
||||||
fake_request = mock.Mock(side_effect=fake_resp)
|
fake_request = mock.Mock(side_effect=fake_resp)
|
||||||
|
|
||||||
|
|
||||||
@mock.patch.multiple('docker.Client', get=fake_request, post=fake_request, put=fake_request, delete=fake_request)
|
@mock.patch.multiple('docker.Client', get=fake_request, post=fake_request,
|
||||||
|
put=fake_request, delete=fake_request)
|
||||||
class DockerClientTest(unittest.TestCase):
|
class DockerClientTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = docker.Client()
|
self.client = docker.Client()
|
||||||
|
@ -74,7 +75,9 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
fake_request.assert_called_with('unix://var/run/docker.sock/v1.4/version')
|
fake_request.assert_called_with(
|
||||||
|
'unix://var/run/docker.sock/v1.4/version'
|
||||||
|
)
|
||||||
|
|
||||||
def test_info(self):
|
def test_info(self):
|
||||||
try:
|
try:
|
||||||
|
@ -90,8 +93,10 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
fake_request.assert_called_with('unix://var/run/docker.sock/v1.4/images/search',
|
fake_request.assert_called_with(
|
||||||
params={'term': 'busybox'})
|
'unix://var/run/docker.sock/v1.4/images/search',
|
||||||
|
params={'term': 'busybox'}
|
||||||
|
)
|
||||||
|
|
||||||
###################
|
###################
|
||||||
## LISTING TESTS ##
|
## LISTING TESTS ##
|
||||||
|
@ -102,8 +107,10 @@ class DockerClientTest(unittest.TestCase):
|
||||||
self.client.images(all=True)
|
self.client.images(all=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
fake_request.assert_called_with('unix://var/run/docker.sock/v1.4/images/json',
|
fake_request.assert_called_with(
|
||||||
params={'filter': None, 'only_ids': 0, 'all': 1})
|
'unix://var/run/docker.sock/v1.4/images/json',
|
||||||
|
params={'filter': None, 'only_ids': 0, 'all': 1}
|
||||||
|
)
|
||||||
|
|
||||||
def test_image_ids(self):
|
def test_image_ids(self):
|
||||||
try:
|
try:
|
||||||
|
@ -111,8 +118,10 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
fake_request.assert_called_with('unix://var/run/docker.sock/v1.4/images/json',
|
fake_request.assert_called_with(
|
||||||
params={'filter': None, 'only_ids': 1, 'all': 0})
|
'unix://var/run/docker.sock/v1.4/images/json',
|
||||||
|
params={'filter': None, 'only_ids': 1, 'all': 0}
|
||||||
|
)
|
||||||
|
|
||||||
def test_list_containers(self):
|
def test_list_containers(self):
|
||||||
try:
|
try:
|
||||||
|
@ -120,7 +129,8 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
fake_request.assert_called_with('unix://var/run/docker.sock/v1.4/containers/ps',
|
fake_request.assert_called_with(
|
||||||
|
'unix://var/run/docker.sock/v1.4/containers/ps',
|
||||||
params={
|
params={
|
||||||
'all': 1,
|
'all': 1,
|
||||||
'since': None,
|
'since': None,
|
||||||
|
@ -141,24 +151,39 @@ class DockerClientTest(unittest.TestCase):
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
args = fake_request.call_args
|
args = fake_request.call_args
|
||||||
self.assertEqual(args[0][0], 'unix://var/run/docker.sock/v1.4/containers/create')
|
self.assertEqual(args[0][0],
|
||||||
self.assertEqual(json.loads(args[0][1]), json.loads('{"Tty": false, "Image": "busybox", "Cmd": ["true"], "AttachStdin": false, "Memory": 0, "AttachStderr": true, "Privileged": false, "AttachStdout": true, "OpenStdin": false}'))
|
'unix://var/run/docker.sock/v1.4/containers/create')
|
||||||
self.assertEqual(args[1]['headers'], {'Content-Type': 'application/json'})
|
self.assertEqual(json.loads(args[0][1]),
|
||||||
|
json.loads('''
|
||||||
|
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
||||||
|
"AttachStdin": false, "Memory": 0,
|
||||||
|
"AttachStderr": true, "Privileged": false,
|
||||||
|
"AttachStdout": true, "OpenStdin": false}'''))
|
||||||
|
self.assertEqual(args[1]['headers'],
|
||||||
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_create_container_with_binds(self):
|
def test_create_container_with_binds(self):
|
||||||
mount_dest = '/mnt'
|
mount_dest = '/mnt'
|
||||||
mount_origin = '/tmp'
|
#mount_origin = '/tmp'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.client.create_container('busybox',
|
self.client.create_container('busybox', ['ls', mount_dest],
|
||||||
['ls', mount_dest], volumes={mount_dest: {}})
|
volumes={mount_dest: {}})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
args = fake_request.call_args
|
args = fake_request.call_args
|
||||||
self.assertEqual(args[0][0], 'unix://var/run/docker.sock/v1.4/containers/create')
|
self.assertEqual(args[0][0],
|
||||||
self.assertEqual(json.loads(args[0][1]), json.loads('{"Tty": false, "Image": "busybox", "Cmd": ["ls", "/mnt"], "AttachStdin": false, "Volumes": {"/mnt": {}}, "Memory": 0, "AttachStderr": true, "Privileged": false, "AttachStdout": true, "OpenStdin": false}'))
|
'unix://var/run/docker.sock/v1.4/containers/create')
|
||||||
self.assertEqual(args[1]['headers'], {'Content-Type': 'application/json'})
|
self.assertEqual(json.loads(args[0][1]),
|
||||||
|
json.loads('''
|
||||||
|
{"Tty": false, "Image": "busybox",
|
||||||
|
"Cmd": ["ls", "/mnt"], "AttachStdin": false,
|
||||||
|
"Volumes": {"/mnt": {}}, "Memory": 0,
|
||||||
|
"AttachStderr": true, "Privileged": false,
|
||||||
|
"AttachStdout": true, "OpenStdin": false}'''))
|
||||||
|
self.assertEqual(args[1]['headers'],
|
||||||
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_create_container_privileged(self):
|
def test_create_container_privileged(self):
|
||||||
try:
|
try:
|
||||||
|
@ -167,9 +192,16 @@ class DockerClientTest(unittest.TestCase):
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
args = fake_request.call_args
|
args = fake_request.call_args
|
||||||
self.assertEqual(args[0][0], 'unix://var/run/docker.sock/v1.4/containers/create')
|
self.assertEqual(args[0][0],
|
||||||
self.assertEqual(json.loads(args[0][1]), json.loads('{"Tty": false, "Image": "busybox", "Cmd": ["true"], "AttachStdin": false, "Memory": 0, "AttachStderr": true, "Privileged": true, "AttachStdout": true, "OpenStdin": false}'))
|
'unix://var/run/docker.sock/v1.4/containers/create')
|
||||||
self.assertEqual(args[1]['headers'], {'Content-Type': 'application/json'})
|
self.assertEqual(json.loads(args[0][1]),
|
||||||
|
json.loads('''
|
||||||
|
{"Tty": false, "Image": "busybox", "Cmd": ["true"],
|
||||||
|
"AttachStdin": false, "Memory": 0,
|
||||||
|
"AttachStderr": true, "Privileged": true,
|
||||||
|
"AttachStdout": true, "OpenStdin": false}'''))
|
||||||
|
self.assertEqual(args[1]['headers'],
|
||||||
|
{'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def test_start_container(self):
|
def test_start_container(self):
|
||||||
try:
|
try:
|
||||||
|
@ -187,7 +219,8 @@ class DockerClientTest(unittest.TestCase):
|
||||||
try:
|
try:
|
||||||
mount_dest = '/mnt'
|
mount_dest = '/mnt'
|
||||||
mount_origin = '/tmp'
|
mount_origin = '/tmp'
|
||||||
self.client.start(fake_api.FAKE_CONTAINER_ID, binds={mount_origin: mount_dest})
|
self.client.start(fake_api.FAKE_CONTAINER_ID,
|
||||||
|
binds={mount_origin: mount_dest})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
|
@ -375,7 +408,8 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
fake_request.assert_called_with('unix://var/run/docker.sock/v1.4/images/create',
|
fake_request.assert_called_with(
|
||||||
|
'unix://var/run/docker.sock/v1.4/images/create',
|
||||||
headers={},
|
headers={},
|
||||||
params={'tag': None, 'fromImage': 'joffrey/test001'}
|
params={'tag': None, 'fromImage': 'joffrey/test001'}
|
||||||
)
|
)
|
||||||
|
@ -405,7 +439,9 @@ class DockerClientTest(unittest.TestCase):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.fail('Command should not raise exception: {0}'.format(e))
|
self.fail('Command should not raise exception: {0}'.format(e))
|
||||||
|
|
||||||
fake_request.assert_called_with('unix://var/run/docker.sock/v1.4/images/e9aa60c60128')
|
fake_request.assert_called_with(
|
||||||
|
'unix://var/run/docker.sock/v1.4/images/e9aa60c60128'
|
||||||
|
)
|
||||||
|
|
||||||
#################
|
#################
|
||||||
# BUILDER TESTS #
|
# BUILDER TESTS #
|
||||||
|
@ -417,7 +453,8 @@ class DockerClientTest(unittest.TestCase):
|
||||||
'MAINTAINER docker-py',
|
'MAINTAINER docker-py',
|
||||||
'RUN mkdir -p /tmp/test',
|
'RUN mkdir -p /tmp/test',
|
||||||
'EXPOSE 8080',
|
'EXPOSE 8080',
|
||||||
'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz /tmp/silence.tar.gz'
|
'ADD https://dl.dropboxusercontent.com/u/20637798/silence.tar.gz'
|
||||||
|
' /tmp/silence.tar.gz'
|
||||||
]).encode('ascii'))
|
]).encode('ascii'))
|
||||||
try:
|
try:
|
||||||
self.client.build(fileobj=script)
|
self.client.build(fileobj=script)
|
||||||
|
|
8
tox.ini
8
tox.ini
|
@ -1,9 +1,13 @@
|
||||||
[tox]
|
[tox]
|
||||||
envlist = py26, py27, py32, py33
|
envlist = py26, py27, py32, py33, flake8
|
||||||
skipsdist=True
|
skipsdist=True
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop=True
|
usedevelop=True
|
||||||
commands =
|
commands =
|
||||||
{envpython} tests/test.py
|
{envpython} tests/test.py
|
||||||
|
|
||||||
deps = -r{toxinidir}/requirements.txt
|
deps = -r{toxinidir}/requirements.txt
|
||||||
|
|
||||||
|
[testenv:flake8]
|
||||||
|
commands = flake8 docker tests
|
||||||
|
deps = flake8
|
Loading…
Reference in New Issue