]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Add unit tests for the Adder in dirnode.py
authorkevan <kevan@isnotajoke.com>
Sat, 18 Jul 2009 19:50:49 +0000 (12:50 -0700)
committerkevan <kevan@isnotajoke.com>
Sat, 18 Jul 2009 19:50:49 +0000 (12:50 -0700)
src/allmydata/test/test_dirnode.py

index 7ed41b2e82180883b3f396e072eabb7835a8edbe..e873337af683fc1a1afe76e7119afa100608bb08 100644 (file)
@@ -966,3 +966,70 @@ class Deleter(GridTestMixin, unittest.TestCase):
 
         return d
 
+class Adder(unittest.TestCase,
+              testutil.ShouldFailMixin, testutil.StallMixin, ErrorMixin):
+
+    def setUp(self):
+        self.client = FakeClient()
+
+    def test_overwrite(self):
+        fileuri = make_chk_file_uri(1234)
+        filenode = self.client.create_node_from_uri(fileuri)
+        d = self.client.create_empty_dirnode()
+
+        def _create_directory_tree(root_node):
+            # Build
+            # root/file1
+            # root/file2
+            # root/dir1
+            d = root_node.add_file(u'file1', upload.Data("Important Things",
+                                                         None))
+            d.addCallback(lambda res:
+                root_node.add_file(u'file2', upload.Data("Sekrit Codes",
+                                                         None)))
+            d.addCallback(lambda res:
+                root_node.create_empty_directory(u"dir1"))
+            d.addCallback(lambda res: root_node)
+            return d
+
+        d.addCallback(_create_directory_tree)
+
+        def _test_adder(root_node):
+            d = root_node.set_node(u'file1', filenode)
+
+            # We've overwritten file1. Let's try it with a directory
+            d.addCallback(lambda res:
+                root_node.create_empty_directory(u'dir2'))
+
+            d.addCallback(lambda res:
+                root_node.set_node(u'dir2', filenode))
+
+            # We try overwriting a file with a child while also specifying
+            # overwrite=False. We should receive an ExistingChildError 
+            # when we do this.
+            d.addCallback(lambda res:
+                self.shouldFail(ExistingChildError, "set_node",
+                                "child 'file1' already exists",
+                               root_node.set_node, u"file1",
+                               filenode, overwrite=False))
+
+            # If we try with a directory, we should see the same thing
+            d.addCallback(lambda res:
+                self.shouldFail(ExistingChildError, "set_node",
+                                "child 'dir1' already exists",
+                                root_node.set_node, u'dir1', filenode,
+                                overwrite=False))
+
+            d.addCallback(lambda res:
+                 root_node.set_node(u'file1', filenode,
+                                    overwrite="only_files"))
+
+            d.addCallback(lambda res:
+                 self.shouldFail(ExistingChildError, "set_node",
+                                "child 'dir1' already exists",
+                                root_node.set_node, u'dir1', filenode,
+                                overwrite="only_files"))
+            return d
+
+        d.addCallback(_test_adder)
+        return d