Merge pull request #1303 from aanand/helpful-containers-warning

Show a helpful warning when people try to call `client.containers()`
This commit is contained in:
Ben Firshman 2016-12-01 11:11:46 +00:00 committed by GitHub
commit e7d78d10f6
2 changed files with 17 additions and 0 deletions

View File

@ -60,6 +60,12 @@ class Collection(object):
#: is on.
self.client = client
def __call__(self, *args, **kwargs):
raise TypeError(
"'{}' object is not callable. You might be trying to use the old "
"(pre-2.0) API - use docker.APIClient if so."
.format(self.__class__.__name__))
def list(self):
raise NotImplementedError

View File

@ -1,5 +1,6 @@
import datetime
import docker
from docker.utils import kwargs_from_env
import os
import unittest
@ -59,6 +60,16 @@ class ClientTest(unittest.TestCase):
assert "'DockerClient' object has no attribute 'abcdef'" in s
assert "this method is now on the object APIClient" not in s
def test_call_containers(self):
client = docker.Client(**kwargs_from_env())
with self.assertRaises(TypeError) as cm:
client.containers()
s = str(cm.exception)
assert "'ContainerCollection' object is not callable" in s
assert "docker.APIClient" in s
class FromEnvTest(unittest.TestCase):