]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
filetree: start testing IVirtualDrive, beginning with list()
authorBrian Warner <warner@lothar.com>
Sun, 21 Jan 2007 04:14:41 +0000 (21:14 -0700)
committerBrian Warner <warner@lothar.com>
Sun, 21 Jan 2007 04:14:41 +0000 (21:14 -0700)
src/allmydata/filetree/directory.py
src/allmydata/filetree/redirect.py
src/allmydata/filetree/vdrive.py
src/allmydata/test/test_filetree_new.py

index 859e36f77094743d05676902cffb57cff15f96b7..91613e6e205081cca5b67fd545f257e87831afbb 100644 (file)
@@ -44,7 +44,7 @@ class SubTreeNode:
 #        self.child_specifications = {}
 
     def list(self):
-        return sorted(self.children.keys())
+        return self.children
 
     def get(self, childname):
         if childname in self.children:
index b7fa12a98b935a7bf91b228529450d3307c13108..bfd540163bf7b99e0de5660dbe5a93586ff7f6ff 100644 (file)
@@ -30,7 +30,7 @@ class _BaseRedirection(object):
         return ([], self.child_node, path)
 
     def serialize_subtree_to_file(self, f):
-        return self.child_node.serialize_node()
+        f.write(self.child_node.serialize_node())
 
     def _populate_from_data(self, data, node_maker):
         assert INodeMaker(node_maker)
index 64e78b69640fa5187869f3a8e04107dda782d68e..63e7271f70cc2ccb22c15d8dc901afa03d56b843 100644 (file)
@@ -46,6 +46,8 @@ class NodeMaker(object):
                 return node
         raise RuntimeError("unable to handle node type '%s'" % prefix)
 
+
+
 all_openable_subtree_types = [
     directory.LocalFileSubTree,
     directory.CHKDirectorySubTree,
@@ -102,6 +104,7 @@ class SubTreeMaker(object):
         return subtree
 
 
+
 class VirtualDrive(object):
     implements(IVirtualDrive)
 
@@ -137,12 +140,8 @@ class VirtualDrive(object):
         return d
 
     def _get_closest_node_1(self, subtree, path):
-        d = subtree.get_node_for_path(path)
-        d.addCallback(self._get_closest_node_2, subtree.is_mutable())
-        return d
-
-    def _get_closest_node_2(self, res, parent_is_mutable):
-        (found_path, node, remaining_path) = res
+        (found_path, node, remaining_path) = subtree.get_node_for_path(path)
+        parent_is_mutable = subtree.is_mutable()
         if IDirectoryNode.providedBy(node):
             # traversal done
             return (node, remaining_path)
index cb592837d183f2f1cacf6e196dd68bb3705ba1ff..6a94e1b58d4d39f688c20b4994c72088e4b9102a 100644 (file)
@@ -335,10 +335,10 @@ class Stuff(unittest.TestCase):
         v = vdrive.VirtualDrive(wq, dl, root_node)
         return v
 
+    def failUnlessListsAreEqual(self, list1, list2):
+        self.failUnlessEqual(sorted(list1), sorted(list2))
+
     def testDirectory(self):
-        # TODO: we only need this VirtualDrive for the opener. Perhaps
-        # make_subtree_from_node should move out of that class and into a
-        # module-level function.
         stm = vdrive.SubTreeMaker(None, None)
 
         # create an empty directory (stored locally)
@@ -352,7 +352,7 @@ class Stuff(unittest.TestCase):
         self.failUnlessEqual(remaining_path, [])
         self.failUnless(INode.providedBy(root))
         self.failUnless(IDirectoryNode.providedBy(root))
-        self.failUnlessEqual(root.list(), [])
+        self.failUnlessListsAreEqual(root.list().keys(), [])
         self.failUnlessIdentical(root.get_subtree(), subtree)
 
         # now add some children to it
@@ -360,13 +360,14 @@ class Stuff(unittest.TestCase):
         file1 = CHKFileNode()
         file1.new("uri1")
         root.add("foo.txt", file1)
-        self.failUnlessEqual(root.list(), ["foo.txt", "subdir1"])
+        self.failUnlessListsAreEqual(root.list().keys(),
+                                     ["foo.txt", "subdir1"])
         self.failUnlessIdentical(root.get("foo.txt"), file1)
         subdir1a = root.get("subdir1")
         self.failUnlessIdentical(subdir1, subdir1a)
         del subdir1a
         self.failUnless(IDirectoryNode.providedBy(subdir1))
-        self.failUnlessEqual(subdir1.list(), [])
+        self.failUnlessListsAreEqual(subdir1.list().keys(), [])
         self.failUnlessIdentical(subdir1.get_subtree(), subtree)
 
         subdir2 = subdir1.add_subdir("subdir2")
@@ -374,7 +375,7 @@ class Stuff(unittest.TestCase):
         subdir4 = subdir2.add_subdir("subdir4")
 
         subdir2.delete("subdir4")
-        self.failUnlessEqual(subdir2.list(), ["subdir3"])
+        self.failUnlessListsAreEqual(subdir2.list().keys(), ["subdir3"])
 
         del root, subdir1, subdir2, subdir3, subdir4
         # leaving file1 for later use
@@ -409,7 +410,8 @@ class Stuff(unittest.TestCase):
             self.failUnlessEqual(remaining_path, [])
             self.failUnless(INode.providedBy(root))
             self.failUnless(IDirectoryNode.providedBy(root))
-            self.failUnlessEqual(root.list(), ["foo.txt", "subdir1"])
+            self.failUnlessListsAreEqual(root.list().keys(),
+                                         ["foo.txt", "subdir1"])
             file1a = root.get("foo.txt")
             self.failUnless(INode(file1a))
             self.failUnless(isinstance(file1a, CHKFileNode))
@@ -417,27 +419,23 @@ class Stuff(unittest.TestCase):
             self.failUnlessEqual(file1a.get_uri(), "uri1")
             subdir1 = root.get("subdir1")
             subdir2 = subdir1.get("subdir2")
-            self.failUnlessEqual(subdir2.list(), ["subdir3"])
+            self.failUnlessListsAreEqual(subdir2.list().keys(), ["subdir3"])
             subdir2.delete("subdir3")
-            self.failUnlessEqual(subdir2.list(), [])
+            self.failUnlessListsAreEqual(subdir2.list().keys(), [])
         d.addCallback(_opened)
         return d
 
     def testVdrive(self):
-        # create some stuff, see if we can import everything
-
-        # create an empty directory (stored locally) as our root
-        root = directory.LocalFileSubTree()
-        root.new("dirtree.save")
-
-        # and a node to point to it
-        root_node = directory.LocalFileSubTreeNode()
-        root_node.new("dirtree.save")
-
-        v = self.makeVirtualDrive("test_filetree_new/testVdrive", root_node)
+        topdir = directory.LocalFileSubTree().new("vdrive-dirtree.save")
+        topdir.update_now(None)
+        root = redirect.LocalFileRedirection().new("vdrive-root",
+                                                   topdir.create_node_now())
+        root.update_now(None)
+        wq = self.makeVirtualDrive("vdrive", root.create_node_now())
+
+        d = wq.list([])
+        def _listed(contents):
+            self.failUnlessEqual(contents, {})
+        d.addCallback(_listed)
+        return d
 
-    def start():
-        root_node = redirect.LocalFileRedirectionNode()
-#        root_node.new("handle", dirtree)
-        root = redirect.LocalFileRedirection()
-        # wow, bootstrapping is hard