summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiuseppe Lavagetto <lavagetto@gmail.com>2014-03-20 13:37:12 +0100
committerGiuseppe Lavagetto <lavagetto@gmail.com>2014-03-20 13:37:12 +0100
commit092e20dbfe8839a56d513876452886fd2cebe76c (patch)
tree6a8c099349694e0ef95e7c0aebff22376f917f53 /src
parent04b65a1c7f5cdaf42060d30ed944de129aef3c97 (diff)
parent14f0ae5361538b9265c64e1e256119913386bf9a (diff)
Merge pull request #37 from jplana/rename-and-extend-children
Rename and extend children
Diffstat (limited to 'src')
-rw-r--r--src/etcd/__init__.py28
-rw-r--r--src/etcd/tests/integration/test_simple.py2
-rw-r--r--src/etcd/tests/unit/test_request.py5
3 files changed, 31 insertions, 4 deletions
diff --git a/src/etcd/__init__.py b/src/etcd/__init__.py
index 63d8865..2f092b0 100644
--- a/src/etcd/__init__.py
+++ b/src/etcd/__init__.py
@@ -38,16 +38,38 @@ class EtcdResult(object):
# We keep the data in raw format, converting them only when needed
self._children = node['nodes']
- @property
- def children(self):
+
+ def get_subtree(self, leaves_only=False):
+ """
+ Get all the subtree resulting from a recursive=true call to etcd.
+
+ Args:
+ leaves_only (bool): if true, only value nodes are returned
+
+
+ """
if not self._children:
+ #if the current result is a leaf, return itself
yield self
return
for n in self._children:
- for child in EtcdResult(None, n).children:
+ node = EtcdResult(None, n)
+ if not leaves_only:
+ #Return also dirs, not just value nodes
+ yield node
+ for child in node.children:
yield child
return
+ @property
+ def leaves(self):
+ return self.get_subtree(leaves_only=True)
+
+ @property
+ def children(self):
+ """ Deprecated, use EtcdResult.leaves instead """
+ return self.leaves
+
def __eq__(self, other):
if not (type(self) is type(other)):
return False
diff --git a/src/etcd/tests/integration/test_simple.py b/src/etcd/tests/integration/test_simple.py
index e13c94a..5ace539 100644
--- a/src/etcd/tests/integration/test_simple.py
+++ b/src/etcd/tests/integration/test_simple.py
@@ -119,7 +119,7 @@ class TestSimple(EtcdIntegrationTest):
set_result = self.client.write('/subtree/test_set1', 'test-key2')
set_result = self.client.write('/subtree/test_set2', 'test-key3')
get_result = self.client.read('/subtree', recursive=True)
- result = [subkey.value for subkey in get_result.children]
+ result = [subkey.value for subkey in get_result.leaves]
self.assertEquals(['test-key1', 'test-key2', 'test-key3'], result)
def test_directory_ttl_update(self):
diff --git a/src/etcd/tests/unit/test_request.py b/src/etcd/tests/unit/test_request.py
index 036f9c0..7103fa1 100644
--- a/src/etcd/tests/unit/test_request.py
+++ b/src/etcd/tests/unit/test_request.py
@@ -100,6 +100,11 @@ class TestClientApiInternals(TestClientApiBase):
class TestClientApiInterface(TestClientApiBase):
+ """
+ All tests defined in this class are executed also in TestClientRequest.
+
+ If a test should be run only in this class, please override the method there.
+ """
def test_machines(self):
""" Can request machines """