diff options
| author | Ben Firshman <ben@firshman.co.uk> | 2016-10-21 17:14:17 +0200 |
|---|---|---|
| committer | Joffrey F <joffrey@docker.com> | 2016-12-07 16:34:53 -0800 |
| commit | 9f49c3bf1a87783dd6c49e9a52cc72b6a05201cf (patch) | |
| tree | c7c7a8c50e944f003dd7b6dbea803895e6efdbe7 | |
| parent | 20439186f36c8928f971f792f1d3a0e1e26ec480 (diff) | |
| download | docker-py-9f49c3bf1a87783dd6c49e9a52cc72b6a05201cf.tar.gz | |
Add helpful error for APIClient methods on Client
Signed-off-by: Ben Firshman <ben@firshman.co.uk>
| -rw-r--r-- | docker/client.py | 10 | ||||
| -rw-r--r-- | tests/unit/client_test.py | 14 |
2 files changed, 24 insertions, 0 deletions
diff --git a/docker/client.py b/docker/client.py index 6c5ae40..b3b4700 100644 --- a/docker/client.py +++ b/docker/client.py @@ -154,4 +154,14 @@ class Client(object): return self.api.version(*args, **kwargs) 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 diff --git a/tests/unit/client_test.py b/tests/unit/client_test.py index e22983c..0a56b04 100644 --- a/tests/unit/client_test.py +++ b/tests/unit/client_test.py @@ -45,6 +45,20 @@ class ClientTest(unittest.TestCase): assert client.version() == mock_func.return_value 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): |
