Skip to content

Commit

Permalink
Merge pull request docker#1303 from aanand/helpful-containers-warning
Browse files Browse the repository at this point in the history
Show a helpful warning when people try to call `client.containers()`
  • Loading branch information
bfirsh authored Dec 1, 2016
2 parents 239673a + 8c27dd5 commit e7d78d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docker/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def __init__(self, client=None):
#: 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

Expand Down
11 changes: 11 additions & 0 deletions tests/unit/client_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import docker
from docker.utils import kwargs_from_env
import os
import unittest

Expand Down Expand Up @@ -59,6 +60,16 @@ def test_call_api_client_method(self):
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):

Expand Down

0 comments on commit e7d78d1

Please sign in to comment.