diff options
author | grahamlyons <graham@grahamlyons.com> | 2017-06-08 14:31:25 +0100 |
---|---|---|
committer | grahamlyons <graham@grahamlyons.com> | 2017-06-08 14:39:17 +0100 |
commit | ee75a1c2e349fccab4a1bcb49142756c9a8495db (patch) | |
tree | 84a4820b0a8dab8cc1cb0cf1529892fea2360e78 | |
parent | dc2b24dcdd4ed7c8f6874ee5dd95716761ab6c93 (diff) | |
download | docker-py-ee75a1c2e349fccab4a1bcb49142756c9a8495db.tar.gz |
Ensure default timeout is used by API Client
The `from_env` method on the `docker` module passed `None` as the
value for the `timeout` keyword argument which overrode the default
value in the initialiser, taken from `constants` module.
This sets the default in the initialiser to `None` and adds logic
to set that, in the same way that `version` is handled.
Signed-off-by: grahamlyons <graham@grahamlyons.com>
-rw-r--r-- | docker/api/client.py | 9 | ||||
-rw-r--r-- | tests/unit/client_test.py | 13 |
2 files changed, 19 insertions, 3 deletions
diff --git a/docker/api/client.py b/docker/api/client.py index 54ec6ab..6822f7c 100644 --- a/docker/api/client.py +++ b/docker/api/client.py @@ -83,8 +83,7 @@ class APIClient( configuration. user_agent (str): Set a custom user agent for requests to the server. """ - def __init__(self, base_url=None, version=None, - timeout=DEFAULT_TIMEOUT_SECONDS, tls=False, + def __init__(self, base_url=None, version=None, timeout=None, tls=False, user_agent=DEFAULT_USER_AGENT, num_pools=DEFAULT_NUM_POOLS): super(APIClient, self).__init__() @@ -94,7 +93,11 @@ class APIClient( ) self.base_url = base_url - self.timeout = timeout + if timeout is not None: + self.timeout = timeout + else: + self.timeout = DEFAULT_TIMEOUT_SECONDS + self.headers['User-Agent'] = user_agent self._auth_configs = auth.load_config() diff --git a/tests/unit/client_test.py b/tests/unit/client_test.py index b79c68e..c4996f1 100644 --- a/tests/unit/client_test.py +++ b/tests/unit/client_test.py @@ -1,6 +1,9 @@ import datetime import docker from docker.utils import kwargs_from_env +from docker.constants import ( + DEFAULT_DOCKER_API_VERSION, DEFAULT_TIMEOUT_SECONDS +) import os import unittest @@ -96,3 +99,13 @@ class FromEnvTest(unittest.TestCase): client = docker.from_env(version='2.32') self.assertEqual(client.api.base_url, "https://192.168.59.103:2376") self.assertEqual(client.api._version, '2.32') + + def test_from_env_without_version_uses_default(self): + client = docker.from_env() + + self.assertEqual(client.api._version, DEFAULT_DOCKER_API_VERSION) + + def test_from_env_without_timeout_uses_default(self): + client = docker.from_env() + + self.assertEqual(client.api.timeout, DEFAULT_TIMEOUT_SECONDS) |