summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Kristensen <john@jerrykan.com>2014-03-13 19:55:29 +1100
committerJohn Kristensen <john@jerrykan.com>2014-03-14 12:23:37 +1100
commit8a320653cbd051389481c978ba1b7494775787cd (patch)
tree84c9fd57ac31ec3a9cfdc34eb1f18f129c981a92 /src
parentef307f1fee32f47541e6d7d76b787a9c134d07ac (diff)
Fix timeout param being incorrectly handled in read()
If the timeout param for read() was set to 0 to indicate that the request should not timeout it would actually then be set to None which would instead use the default timeout value.
Diffstat (limited to 'src')
-rw-r--r--src/etcd/client.py2
-rw-r--r--src/etcd/tests/unit/test_request.py46
2 files changed, 47 insertions, 1 deletions
diff --git a/src/etcd/client.py b/src/etcd/client.py
index 45d7fbb..4dccdd8 100644
--- a/src/etcd/client.py
+++ b/src/etcd/client.py
@@ -306,7 +306,7 @@ class Client(object):
else:
params[k] = v
- timeout = 'timeout' in kwdargs and kwdargs['timeout'] or None
+ timeout = kwdargs.get('timeout', None)
response = self.api_execute(
self.key_endpoint + key, self._MGET, params=params, timeout=timeout)
diff --git a/src/etcd/tests/unit/test_request.py b/src/etcd/tests/unit/test_request.py
index 886805e..aae3e56 100644
--- a/src/etcd/tests/unit/test_request.py
+++ b/src/etcd/tests/unit/test_request.py
@@ -35,6 +35,52 @@ class TestClientApiBase(unittest.TestCase):
def _mock_exception(self, exc, msg):
self.client.api_execute = mock.Mock(side_effect=exc(msg))
+
+class TestClientApiInternals(TestClientApiBase):
+
+ def test_read_default_timeout(self):
+ """ Read timeout set to the default """
+ d = {
+ u'action': u'get',
+ u'node': {
+ u'modifiedIndex': 190,
+ u'key': u'/testkey',
+ u'value': u'test'
+ }
+ }
+ self._mock_api(200, d)
+ res = self.client.read('/testkey')
+ self.assertEqual(self.client.api_execute.call_args[1]['timeout'], None)
+
+ def test_read_custom_timeout(self):
+ """ Read timeout set to the supplied value """
+ d = {
+ u'action': u'get',
+ u'node': {
+ u'modifiedIndex': 190,
+ u'key': u'/testkey',
+ u'value': u'test'
+ }
+ }
+ self._mock_api(200, d)
+ self.client.read('/testkey', timeout=15)
+ self.assertEqual(self.client.api_execute.call_args[1]['timeout'], 15)
+
+ def test_read_no_timeout(self):
+ """ Read timeout disabled """
+ d = {
+ u'action': u'get',
+ u'node': {
+ u'modifiedIndex': 190,
+ u'key': u'/testkey',
+ u'value': u'test'
+ }
+ }
+ self._mock_api(200, d)
+ self.client.read('/testkey', timeout=0)
+ self.assertEqual(self.client.api_execute.call_args[1]['timeout'], 0)
+
+
class TestClientApiInterface(TestClientApiBase):
def test_machines(self):