diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-09-12 12:10:43 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-09-12 12:10:43 -0700 |
commit | ea62590db48bf26aa3a1dbeeed1dfaf385a4a175 (patch) | |
tree | bb601390b0673e862850007dfccb9ab2344fee8c | |
parent | 9a92e8e8695ebabffa6c2d000e48afc17de3484a (diff) | |
download | zake-ea62590db48bf26aa3a1dbeeed1dfaf385a4a175.tar.gz |
Correctly handle get_children() with a path that does not exist
-rw-r--r-- | zake/fake_client.py | 11 | ||||
-rw-r--r-- | zake/tests/test_client.py | 8 |
2 files changed, 16 insertions, 3 deletions
diff --git a/zake/fake_client.py b/zake/fake_client.py index 3cca788..73992a2 100644 --- a/zake/fake_client.py +++ b/zake/fake_client.py @@ -300,7 +300,11 @@ class FakeClient(object): return p.strip("/") path = utils.normpath(path) - paths = self.storage.get_children(path) + with self.storage.lock: + if path not in self.storage: + raise k_exceptions.NoNodeError("Node %s does not exist" + % (path)) + paths = self.storage.get_children(path) if watch: with self._watches_lock: self._child_watches[path].append(watch) @@ -413,7 +417,8 @@ class _PartialClient(object): path = utils.normpath(path) with self.storage.lock: if path not in self.storage: - raise k_exceptions.NoNodeError("No path %s" % (path)) + raise k_exceptions.NoNodeError("Node %s does not exist" + % (path)) path_version = self.storage[path]['version'] if version != -1 and path_version != version: raise k_exceptions.BadVersionError("Version mismatch" @@ -464,7 +469,7 @@ class _PartialClient(object): try: stat = self.storage.set(path, value, version=version) except KeyError: - raise k_exceptions.NoNodeError("No path %s" % (path)) + raise k_exceptions.NoNodeError("Node %s does not exist" % (path)) data_watches = [] child_watches = [] event = k_states.WatchedEvent(type=k_states.EventType.CHANGED, diff --git a/zake/tests/test_client.py b/zake/tests/test_client.py index ce74063..334cc05 100644 --- a/zake/tests/test_client.py +++ b/zake/tests/test_client.py @@ -446,6 +446,7 @@ class TestClient(test.Test): return False with start_close(self.client) as c: + c.ensure_path("/b") k_watchers.ChildrenWatch(self.client, "/b", func=one_time_collector_func) c.ensure_path("/b/c") @@ -453,6 +454,13 @@ class TestClient(test.Test): self.assertEqual(['c'], list(updates)) + def test_child_watch_no_create(self): + cb = lambda *args, **kwargs: None + with start_close(self.client) as c: + self.assertRaises(k_exceptions.NoNodeError, + k_watchers.ChildrenWatch, + self.client, "/b", cb) + def test_create_sequence(self): with start_close(self.client) as c: path = c.create("/a", sequence=True) |