]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Teach magic-folder tests to use CLI for creating magic folder config
authorDavid Stainton <dstainton415@gmail.com>
Wed, 24 Jun 2015 21:22:34 +0000 (14:22 -0700)
committerDaira Hopwood <daira@jacaranda.org>
Thu, 1 Oct 2015 00:19:44 +0000 (01:19 +0100)
src/allmydata/frontends/magic_folder.py
src/allmydata/scripts/magic_folder_cli.py
src/allmydata/test/test_magic_folder.py

index 4adfffae852ee137ba6df89422466e4090040b38..4a7fc4cad12c7c1c1087ed235d93a2e2d82c5283 100644 (file)
@@ -217,7 +217,7 @@ class MagicFolder(service.MultiService):
                           "(this is normal for temporary objects)" % (path,))
                 self._stats_provider.count('magic_folder.objects_disappeared', 1)
 
-                d2 = defer.Succeed(None)
+                d2 = defer.succeed(None)
                 if not self._db.check_file_db_exists(path):
                     pass
                 else:
index a86e6439cb734f82a2db42da4c01f4a113f691cc..b0cc8a2357b78293aa8df8b66208aa4496789eeb 100644 (file)
@@ -8,6 +8,7 @@ from .common import BaseOptions, BasedirOptions, get_aliases
 from .cli import MakeDirectoryOptions, ListOptions, LnOptions
 import tahoe_ls, tahoe_mv
 from allmydata.util import fileutil
+from allmydata.util.fileutil import abspath_expanduser_unicode
 
 
 INVITE_SEPERATOR = "~"
@@ -155,7 +156,7 @@ def join(options):
 
     fileutil.write(dmd_cap_file, dmd_write_cap)
     fileutil.write(collective_readcap_file, magic_readonly_cap)
-    fileutil.write(os.path.join(options["node-directory"], "tahoe.cfg"), "[magic_folder]\nenabled = True\nlocal.directory = %s\n" % (options.local_dir,))
+    fileutil.write(os.path.join(options["node-directory"], "tahoe.cfg"), "[magic_folder]\nenabled = True\nlocal.directory = %s\n" % (options.local_dir.encode('utf-8'),), mode="ab")
     return 0
 
 class MagicFolderCommand(BaseOptions):
index 9ee372dc2134d8785bc1d7ead9ee2a8b9ed5ac50..2eeb52908c837ff90041cd4f3c99698cf03672db 100644 (file)
@@ -1,5 +1,5 @@
 
-import os, sys, stat, time
+import os, sys, stat, time, json, re
 
 from twisted.trial import unittest
 from twisted.internet import defer
@@ -12,6 +12,7 @@ from allmydata.util.consumer import download_to_data
 from allmydata.test.no_network import GridTestMixin
 from allmydata.test.common_util import ReallyEqualMixin, NonASCIIPathMixin
 from allmydata.test.common import ShouldFailMixin
+from allmydata.test.test_cli import CLITestMixin
 
 from allmydata.frontends import magic_folder
 from allmydata.frontends.magic_folder import MagicFolder
@@ -19,7 +20,7 @@ from allmydata import backupdb
 from allmydata.util.fileutil import abspath_expanduser_unicode
 
 
-class MagicFolderTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonASCIIPathMixin):
+class MagicFolderTestMixin(CLITestMixin, GridTestMixin, ShouldFailMixin, ReallyEqualMixin, NonASCIIPathMixin):
     """
     These tests will be run both with a mock notifier, and (on platforms that support it)
     with the real INotify.
@@ -42,6 +43,56 @@ class MagicFolderTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, Non
         self.failUnlessEqual(bdb.VERSION, 2)
         return bdb
 
+    def _diminish(self, write_cap):
+        d = self.do_cli("ls", "--json", write_cap)
+        def get_readonly_cap((rc,stdout,stderr)):
+            self.failUnless(rc == 0)
+            readonly_cap = json.loads(stdout)[1][u"ro_uri"]
+            return readonly_cap
+        d.addCallback(get_readonly_cap)
+        return d
+
+    def _try_joined_config(self, result):
+        collective_readonly_cap = fileutil.read(os.path.join(self.get_clientdir(), "private/collective_dircap"))
+        d = self.do_cli("ls", "--json", collective_readonly_cap)
+        def _done((rc,stdout,stderr)):
+            self.failUnless(rc == 0)
+            return (rc,stdout,stderr)
+        d.addCallback(_done)
+        def test_joined_magic_folder((rc,stdout,stderr)):
+            d2 = self._diminish(self.upload_dircap)
+            def fail_unless_dmd_readonly_exists(readonly_cap):
+                s = re.search(readonly_cap, stdout)
+                self.failUnless(s is not None)
+            d2.addCallback(fail_unless_dmd_readonly_exists)
+            return d2
+        d.addCallback(test_joined_magic_folder)
+        return d
+
+    def _get_caps_from_files(self, result):
+        self.collective_dircap = fileutil.read(os.path.join(self.get_clientdir(), "private/collective_dircap"))
+        self.upload_dircap = fileutil.read(os.path.join(self.get_clientdir(), "private/magic_folder_dircap"))
+        self.failIf(self.collective_dircap is None or self.upload_dircap is None)
+
+    def _check_config(self, result):
+        client_config = fileutil.read(os.path.join(self.get_clientdir(), "tahoe.cfg"))
+        print "CLIENT CONFIG", client_config
+        # XXX utf-8
+        ret = re.search("\[magic_folder\]\nenabled = True\nlocal.directory = %s" % (self.local_dir.encode('utf-8'),), client_config)
+        self.failIf(ret is None)
+        return result
+
+    def _create_invite_join_magic_folder(self):
+        d = self.do_cli("magic-folder", "create", u"magic", u"Alice", self.local_dir)
+        def _done((rc,stdout,stderr)):
+            self.failUnless(rc == 0)
+            return (rc,stdout,stderr)
+        d.addCallback(_done)
+        d.addCallback(self._get_caps_from_files)
+        d.addCallback(self._try_joined_config)
+        d.addCallback(self._check_config)
+        return d
+
     def _made_upload_dir(self, n):
         if self.dir_node == None:
             self.dir_node = n
@@ -136,9 +187,7 @@ class MagicFolderTestMixin(GridTestMixin, ShouldFailMixin, ReallyEqualMixin, Non
         small_tree_dir = abspath_expanduser_unicode(small_tree_name, base=self.basedir)
         new_small_tree_dir = abspath_expanduser_unicode(small_tree_name, base=self.local_dir)
 
-        d = self.client.create_dirnode()
-        d.addCallback(self._made_upload_dir)
-
+        d = self._create_invite_join_magic_folder()
         d.addCallback(self._create_magicfolder)
 
         def _check_move_empty_tree(res):