Unverified Kaydet (Commit) 8c27dd52 authored tarafından Aanand Prasad's avatar Aanand Prasad Kaydeden (comit) Ben Firshman

Show a helpful warning when people try to call `client.containers()`

People upgrading to docker-py 2.0 without being aware of the new client
API will likely try to call the old `containers()` method. This adds a
helpful warning telling them to use APIClient to get the old API.
Signed-off-by: 's avatarAanand Prasad <aanand.prasad@gmail.com>
üst f051f7e9
...@@ -60,6 +60,12 @@ class Collection(object): ...@@ -60,6 +60,12 @@ class Collection(object):
#: is on. #: is on.
self.client = client 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): def list(self):
raise NotImplementedError raise NotImplementedError
......
import datetime import datetime
import docker import docker
from docker.utils import kwargs_from_env
import os import os
import unittest import unittest
...@@ -59,6 +60,16 @@ class ClientTest(unittest.TestCase): ...@@ -59,6 +60,16 @@ class ClientTest(unittest.TestCase):
assert "'Client' object has no attribute 'abcdef'" in s assert "'Client' object has no attribute 'abcdef'" in s
assert "this method is now on the object APIClient" not 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): class FromEnvTest(unittest.TestCase):
......
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