From 59ee02e82f0bacc0aec3d85ddd81a48fff2b881c Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Sat, 17 Oct 2009 12:41:59 -0700
Subject: [PATCH] test_dirnode.py: add tests of initial_children= args to
 client.create_dirnode and nodemaker.create_new_mutable_directory

---
 src/allmydata/test/test_dirnode.py | 32 ++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/allmydata/test/test_dirnode.py b/src/allmydata/test/test_dirnode.py
index a4313dee..aed7e9d7 100644
--- a/src/allmydata/test/test_dirnode.py
+++ b/src/allmydata/test/test_dirnode.py
@@ -36,6 +36,38 @@ class Dirnode(GridTestMixin, unittest.TestCase,
         d.addCallback(_done)
         return d
 
+    def test_initial_children(self):
+        self.basedir = "dirnode/Dirnode/test_initial_children"
+        self.set_up_grid()
+        c = self.g.clients[0]
+        setup_py_uri = "URI:CHK:n7r3m6wmomelk4sep3kw5cvduq:os7ijw5c3maek7pg65e5254k2fzjflavtpejjyhshpsxuqzhcwwq:3:20:14861"
+        one_uri = "URI:LIT:n5xgk" # LIT for "one"
+        kids = {u"one": (c.nodemaker.create_from_cap(one_uri), {}),
+                u"two": (c.nodemaker.create_from_cap(setup_py_uri),
+                         {"metakey": "metavalue"}),
+                }
+        d = c.create_dirnode(kids)
+        def _created(dn):
+            self.failUnless(isinstance(dn, dirnode.DirectoryNode))
+            rep = str(dn)
+            self.failUnless("RW" in rep)
+            return dn.list()
+        d.addCallback(_created)
+        def _check_kids(children):
+            self.failUnlessEqual(sorted(children.keys()), [u"one", u"two"])
+            one_node, one_metadata = children[u"one"]
+            two_node, two_metadata = children[u"two"]
+            self.failUnlessEqual(one_node.get_size(), 3)
+            self.failUnlessEqual(two_node.get_size(), 14861)
+            self.failUnless(isinstance(one_metadata, dict), one_metadata)
+            self.failUnlessEqual(two_metadata["metakey"], "metavalue")
+        d.addCallback(_check_kids)
+        d.addCallback(lambda ign:
+                      c.nodemaker.create_new_mutable_directory(kids))
+        d.addCallback(lambda dn: dn.list())
+        d.addCallback(_check_kids)
+        return d
+
     def test_check(self):
         self.basedir = "dirnode/Dirnode/test_check"
         self.set_up_grid()
-- 
2.45.2