summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAanand Prasad <aanand.prasad@gmail.com>2016-11-23 14:33:57 +0000
committerBen Firshman <ben@firshman.co.uk>2016-11-28 19:43:49 +0000
commit8c27dd52335c55055a0e565ea4421d4e7c5ffdfb (patch)
tree9fd39e5ffcb001d23b9e936270b194d3488b89d1
parentf051f7e90a26e83e1ea5ae2957fa4c3602a07eca (diff)
downloaddocker-py-8c27dd52335c55055a0e565ea4421d4e7c5ffdfb.tar.gz
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: Aanand Prasad <aanand.prasad@gmail.com>
-rw-r--r--docker/models/resource.py6
-rw-r--r--tests/unit/client_test.py11
2 files changed, 17 insertions, 0 deletions
diff --git a/docker/models/resource.py b/docker/models/resource.py
index 9634a24..95712ae 100644
--- a/docker/models/resource.py
+++ b/docker/models/resource.py
@@ -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
diff --git a/tests/unit/client_test.py b/tests/unit/client_test.py
index 0a56b04..e40063f 100644
--- a/tests/unit/client_test.py
+++ b/tests/unit/client_test.py
@@ -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 "'Client' 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):