]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
unit-test for delete case (using @inlineCallbacks)
authormeejah <meejah@meejah.ca>
Thu, 8 Oct 2015 19:00:25 +0000 (13:00 -0600)
committermeejah <meejah@meejah.ca>
Mon, 26 Oct 2015 14:07:23 +0000 (08:07 -0600)
src/allmydata/test/test_magic_folder.py

index 528bb0d5069c5b1f8e2f920eb59cc1ff56bde52c..c14edc8e5ea5dc0f73a74151129922967d14b217 100644 (file)
@@ -241,6 +241,43 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
         d.addBoth(self.cleanup)
         return d
 
+    @defer.inlineCallbacks
+    def test_delete(self):
+        self.set_up_grid()
+        self.local_dir = os.path.join(self.basedir, u"local_dir")
+        self.mkdir_nonascii(self.local_dir)
+
+        yield self.create_invite_join_magic_folder(u"Alice\u0101", self.local_dir)
+        yield self._restart_client(None)
+
+        try:
+            # create a file
+            up_proc = self.magicfolder.uploader.set_hook('processed')
+            down_proc = self.magicfolder.downloader.set_hook('processed')
+            path = os.path.join(self.local_dir, u'foo')
+            with open(path, 'w') as f:
+                f.write('foo\n')
+            self.notify(to_filepath(path), self.inotify.IN_CLOSE_WRITE)
+            x = yield up_proc
+            self.assertIs(x, None)  # some things "return" an Exception instead of raising it
+            self.assertTrue(os.path.exists(path))
+
+            # the real test part: delete the file
+            proc = self.magicfolder.uploader.set_hook('processed')
+            os.unlink(path)
+            self.notify(to_filepath(path), self.inotify.IN_DELETE)
+            x = yield proc
+            self.assertIs(x, None)
+            self.assertFalse(os.path.exists(path))
+
+            # ensure we still have a DB entry, and that the version is 1
+            node, metadata = yield self.magicfolder.downloader._get_collective_latest_file(u'foo')
+            self.assertTrue(node is not None, "Failed to find '{}' in DMD".format(path))
+            self.failUnlessEqual(metadata['version'], 1)
+
+        finally:
+            yield self.cleanup(None)
+
     def test_magic_folder(self):
         self.set_up_grid()
         self.local_dir = os.path.join(self.basedir, self.unicode_or_fallback(u"loc\u0101l_dir", u"local_dir"))