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>
This commit is contained in:
grahamlyons 2017-06-08 14:31:25 +01:00
parent dc2b24dcdd
commit ee75a1c2e3
2 changed files with 19 additions and 3 deletions

View File

@ -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()

View File

@ -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)