Unverified Kaydet (Commit) b5f7d380 authored tarafından Ben Firshman's avatar Ben Firshman

Add helpful error for APIClient methods on Client

Signed-off-by: 's avatarBen Firshman <ben@firshman.co.uk>
üst c7a3aa7e
...@@ -154,4 +154,14 @@ class Client(object): ...@@ -154,4 +154,14 @@ class Client(object):
return self.api.version(*args, **kwargs) return self.api.version(*args, **kwargs)
version.__doc__ = APIClient.version.__doc__ version.__doc__ = APIClient.version.__doc__
def __getattr__(self, name):
s = ["'Client' object has no attribute '{}'".format(name)]
# If a user calls a method on APIClient, they
if hasattr(APIClient, name):
s.append("In docker-py 2.0, this method is now on the object "
"APIClient. See the low-level API section of the "
"documentation for more details.".format(name))
raise AttributeError(' '.join(s))
from_env = Client.from_env from_env = Client.from_env
...@@ -45,6 +45,20 @@ class ClientTest(unittest.TestCase): ...@@ -45,6 +45,20 @@ class ClientTest(unittest.TestCase):
assert client.version() == mock_func.return_value assert client.version() == mock_func.return_value
mock_func.assert_called_with() mock_func.assert_called_with()
def test_call_api_client_method(self):
client = docker.from_env()
with self.assertRaises(AttributeError) as cm:
client.create_container()
s = str(cm.exception)
assert "'Client' object has no attribute 'create_container'" in s
assert "this method is now on the object APIClient" in s
with self.assertRaises(AttributeError) as cm:
client.abcdef()
s = str(cm.exception)
assert "'Client' object has no attribute 'abcdef'" in s
assert "this method is now on the object APIClient" not 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