get rid of another diminish hack and force alias args to end with ':'
authorDavid Stainton <dstainton415@gmail.com>
Wed, 15 Jul 2015 21:22:15 +0000 (14:22 -0700)
committerDaira Hopwood <daira@jacaranda.org>
Thu, 1 Oct 2015 00:19:45 +0000 (01:19 +0100)
src/allmydata/scripts/magic_folder_cli.py
src/allmydata/test/test_cli_magic_folder.py

index 3ffad476903590494cd36e71be3e2eab2451922d..082c08eaf8db69ce525473b77249dec8d3290cd0 100644 (file)
@@ -17,7 +17,9 @@ class CreateOptions(BasedirOptions):
     synopsis = "MAGIC_ALIAS: [NICKNAME LOCALDIR]"
     def parseArgs(self, alias, nickname=None, localdir=None):
         BasedirOptions.parseArgs(self)
-        self.alias = alias
+        if not alias.endswith(':'):
+            raise usage.UsageError("An alias must end with a ':' character.")
+        self.alias = alias[:-1]
         self.nickname = nickname
         self.localdir = localdir
         if self.nickname and not self.localdir:
@@ -64,7 +66,9 @@ class InviteOptions(BasedirOptions):
     stdin = StringIO("")
     def parseArgs(self, alias, nickname=None):
         BasedirOptions.parseArgs(self)
-        self.alias = alias
+        if not alias.endswith(':'):
+            raise usage.UsageError("An alias must end with a ':' character.")
+        self.alias = alias[:-1]
         self.nickname = nickname
         node_url_file = os.path.join(self['node-directory'], "node.url")
         self['node-url'] = open(node_url_file, "r").read().strip()
index a1a03c2d381de9fd71ea0c735eaf5677c9661d78..d5b4839a7a44820374c1c4dd0a495903b55a69ff 100644 (file)
@@ -12,12 +12,12 @@ from .test_cli import CLITestMixin
 from allmydata.scripts import magic_folder_cli
 from allmydata.util.fileutil import abspath_expanduser_unicode
 from allmydata.frontends.magic_folder import MagicFolder
-
+from allmydata import uri
 
 class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
 
     def create_magic_folder(self, client_num):
-        d = self.do_cli("magic-folder", "create", "magic", client_num=client_num)
+        d = self.do_cli("magic-folder", "create", "magic:", client_num=client_num)
         def _done((rc,stdout,stderr)):
             self.failUnless(rc == 0)
             self.failUnless("Alias 'magic' created" in stdout)
@@ -29,7 +29,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         return d
 
     def invite(self, client_num, nickname):
-        d = self.do_cli("magic-folder", "invite", u"magic", nickname, client_num=client_num)
+        d = self.do_cli("magic-folder", "invite", u"magic:", nickname, client_num=client_num)
         def _done((rc,stdout,stderr)):
             self.failUnless(rc == 0)
             return (rc,stdout,stderr)
@@ -45,15 +45,6 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         d.addCallback(_done)
         return d
 
-    def diminish_readonly(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 check_joined_config(self, client_num, upload_dircap):
         """Tests that our collective directory has the readonly cap of
         our upload directory.
@@ -65,12 +56,10 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
             return (rc,stdout,stderr)
         d.addCallback(_done)
         def test_joined_magic_folder((rc,stdout,stderr)):
-            d2 = self.diminish_readonly(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
+            readonly_cap = unicode(uri.from_string(upload_dircap).get_readonly().to_string(), 'utf-8')
+            s = re.search(readonly_cap, stdout)
+            self.failUnless(s is not None)
+            return None
         d.addCallback(test_joined_magic_folder)
         return d
 
@@ -88,7 +77,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
         self.failIf(ret is None)
 
     def create_invite_join_magic_folder(self, nickname, local_dir):
-        d = self.do_cli("magic-folder", "create", u"magic", nickname, local_dir)
+        d = self.do_cli("magic-folder", "create", u"magic:", nickname, local_dir)
         def _done((rc,stdout,stderr)):
             self.failUnless(rc == 0)
             return (rc,stdout,stderr)
@@ -185,7 +174,7 @@ class CreateMagicFolder(MagicFolderCLITestMixin, unittest.TestCase):
         self.basedir = "cli/MagicFolder/create-invite-join"
         self.set_up_grid()
         self.local_dir = os.path.join(self.basedir, "magic")
-        d = self.do_cli("magic-folder", "create", u"magic", u"Alice", self.local_dir)
+        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)