From: David Stainton Date: Tue, 30 Jun 2015 01:08:53 +0000 (-0700) Subject: teach setup_alice_and_bob to return results in deferred X-Git-Url: https://git.rkrishnan.org/%5B/frontends/%22news.html/%22doc.html/nxhtml.html?a=commitdiff_plain;h=33c20703afdcb40295bad6c35b8dfe191469148a;p=tahoe-lafs%2Ftahoe-lafs.git teach setup_alice_and_bob to return results in deferred - however it is terrible that i was unable to set local vars in the callbacks so i had to use object attributes instead. --- diff --git a/src/allmydata/test/test_cli_magic_folder.py b/src/allmydata/test/test_cli_magic_folder.py index 407a048c..b97ee0d0 100644 --- a/src/allmydata/test/test_cli_magic_folder.py +++ b/src/allmydata/test/test_cli_magic_folder.py @@ -14,6 +14,7 @@ from allmydata.util.encodingutil import quote_output, get_io_encoding 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 class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): @@ -39,6 +40,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): return d def join(self, client_num, local_dir, invite_code): + print "INVITE CODE ", invite_code magic_readonly_cap, dmd_write_cap = invite_code.split(magic_folder_cli.INVITE_SEPERATOR) d = self.do_cli_n(client_num, "magic-folder", "join", invite_code, local_dir) def _done((rc,stdout,stderr)): @@ -128,36 +130,37 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin): bob_magic_dir = abspath_expanduser_unicode(u"Bob-magic", base=self.basedir) self.mkdir_nonascii(bob_magic_dir) d = self.create_magic_folder(0) - d.addCallback(lambda x: self.invite_n(0, x)) - d.addCallback(lambda x: self.join(0, alice_magic_dir, x)) + d.addCallback(lambda x: self.invite(0, u"Alice")) + def get_invitecode(result): + self.invitecode = result[1].strip() + d.addCallback(get_invitecode) + d.addCallback(lambda x: self.join(0, alice_magic_dir, self.invitecode)) def get_alice_caps(x): - alice_collective_dircap, alice_upload_dircap = self.get_caps_from_files(0) + self.alice_collective_dircap, self.alice_upload_dircap = self.get_caps_from_files(0) d.addCallback(get_alice_caps) - d.addCallback(lambda x: self.check_joined_config(0, alice_upload_dircap)) + d.addCallback(lambda x: self.check_joined_config(0, self.alice_upload_dircap)) d.addCallback(lambda x: self.check_config(0, alice_magic_dir)) def get_Alice_magicfolder(result): - self.alice_magicfolder = self.init_magicfolder(0, alice_upload_dircap, alice_collective_dircap, alice_magic_dir) + self.alice_magicfolder = self.init_magicfolder(0, self.alice_upload_dircap, self.alice_collective_dircap, alice_magic_dir) return result d.addCallback(get_Alice_magicfolder) - d.addCallback(lambda x: self.invite_n(0, u"Bob")) - d.addCallback(lambda x: self.join(1, bob_magic_dir, x)) + d.addCallback(lambda x: self.invite(0, u"Bob")) + def get_invitecode(result): + self.invitecode = result[1].strip() + d.addCallback(get_invitecode) + d.addCallback(lambda x: self.join(1, bob_magic_dir, self.invitecode)) def get_bob_caps(x): - bob_collective_dircap, bob_upload_dircap = self.get_caps_from_files(1) + self.bob_collective_dircap, self.bob_upload_dircap = self.get_caps_from_files(1) d.addCallback(get_bob_caps) - d.addCallback(lambda x: self.check_joined_config(1, bob_upload_dircap)) + d.addCallback(lambda x: self.check_joined_config(1, self.bob_upload_dircap)) d.addCallback(lambda x: self.check_config(1, bob_magic_dir)) def get_Bob_magicfolder(result): - self.bob_magicfolder = self.init_magicfolder(1, bob_upload_dircap, bob_collective_dircap, bob_magic_dir) + self.bob_magicfolder = self.init_magicfolder(1, self.bob_upload_dircap, self.bob_collective_dircap, bob_magic_dir) return result d.addCallback(get_Bob_magicfolder) - - def cleanup_Alice_and_Bob(result): - d = defer.succeed(None) - d.addCallback(lambda ign: self.alice_magicfolder.finish(for_tests=True)) - d.addCallback(lambda ign: self.bob_magicfolder.finish(for_tests=True)) - d.addCallback(lambda ign: result) - return d - d.addCallback(cleanup_Alice_and_Bob) + def prepare_result(result): + return self.alice_collective_dircap, self.alice_upload_dircap, self.alice_magicfolder, self.bob_collective_dircap, self.bob_upload_dircap, self.bob_magicfolder + d.addCallback(prepare_result) return d class CreateMagicFolder(MagicFolderCLITestMixin, unittest.TestCase): diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index a7adfa8c..6729fdd2 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -316,7 +316,20 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual return d def test_alice_bob(self): - self.setup_alice_and_bob() + d = self.setup_alice_and_bob() + def get_results(result): + # XXX + self.alice_collective_dir, self.alice_upload_dircap, self.alice_magicfolder, self.bob_collective_dircap, self.bob_upload_dircap, self.bob_magicfolder = result + d.addCallback(get_results) + + def cleanup_Alice_and_Bob(result): + d = defer.succeed(None) + d.addCallback(lambda ign: self.alice_magicfolder.finish(for_tests=True)) + d.addCallback(lambda ign: self.bob_magicfolder.finish(for_tests=True)) + d.addCallback(lambda ign: result) + return d + d.addCallback(cleanup_Alice_and_Bob) + return d class MockTest(MagicFolderTestMixin, unittest.TestCase): """This can run on any platform, and even if twisted.internet.inotify can't be imported."""