diff options
author | Joffrey F <f.joffrey@gmail.com> | 2014-11-26 14:28:47 -0800 |
---|---|---|
committer | Joffrey F <f.joffrey@gmail.com> | 2014-11-26 14:28:47 -0800 |
commit | 2cdefc97d9c4c08395c07cc8e371fa3d9a5760a0 (patch) | |
tree | c81c1f37a2cafd52ba8695f729bbeded56275a53 | |
parent | 2a90dd2ab50bacd1a314c86da276b41fa1b6c229 (diff) | |
parent | a9bc84cece547d101069afd195d1500f67e3a44a (diff) | |
download | docker-py-2cdefc97d9c4c08395c07cc8e371fa3d9a5760a0.tar.gz |
Merge pull request #411 from docker/393-enforce-str-version
Enforce passing string as version param in ctor
-rw-r--r-- | docker/client.py | 6 | ||||
-rw-r--r-- | tests/test.py | 11 |
2 files changed, 17 insertions, 0 deletions
diff --git a/docker/client.py b/docker/client.py index 5ba9003..93f4bd7 100644 --- a/docker/client.py +++ b/docker/client.py @@ -50,6 +50,12 @@ class Client(requests.Session): raise errors.TLSParameterError( 'If using TLS, the base_url argument must begin with ' '"https://".') + if not isinstance(version, six.string_types): + raise errors.DockerException( + 'version parameter must be a string. Found {0}'.format( + type(version).__name__ + ) + ) self.base_url = base_url self._version = version self._timeout = timeout diff --git a/tests/test.py b/tests/test.py index c9a1b05..38cbc2f 100644 --- a/tests/test.py +++ b/tests/test.py @@ -102,6 +102,17 @@ class DockerClientTest(Cleanup, unittest.TestCase): def tearDown(self): self.client.close() + def test_ctor(self): + try: + docker.Client(version=1.12) + except Exception as e: + self.assertTrue(isinstance(e, docker.errors.DockerException)) + if not six.PY3: + self.assertEqual( + e.message, + 'version parameter must be a string. Found float' + ) + ######################### # INFORMATION TESTS # ######################### |