mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-02 03:06:41 +00:00
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.
This commit is contained in:
parent
a5c0907580
commit
df1c93629d
@ -14,6 +14,7 @@ from allmydata.util.encodingutil import quote_output, get_io_encoding
|
|||||||
from .test_cli import CLITestMixin
|
from .test_cli import CLITestMixin
|
||||||
from allmydata.scripts import magic_folder_cli
|
from allmydata.scripts import magic_folder_cli
|
||||||
from allmydata.util.fileutil import abspath_expanduser_unicode
|
from allmydata.util.fileutil import abspath_expanduser_unicode
|
||||||
|
from allmydata.frontends.magic_folder import MagicFolder
|
||||||
|
|
||||||
|
|
||||||
class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
|
class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
|
||||||
@ -39,6 +40,7 @@ class MagicFolderCLITestMixin(CLITestMixin, GridTestMixin):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def join(self, client_num, local_dir, invite_code):
|
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)
|
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)
|
d = self.do_cli_n(client_num, "magic-folder", "join", invite_code, local_dir)
|
||||||
def _done((rc,stdout,stderr)):
|
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)
|
bob_magic_dir = abspath_expanduser_unicode(u"Bob-magic", base=self.basedir)
|
||||||
self.mkdir_nonascii(bob_magic_dir)
|
self.mkdir_nonascii(bob_magic_dir)
|
||||||
d = self.create_magic_folder(0)
|
d = self.create_magic_folder(0)
|
||||||
d.addCallback(lambda x: self.invite_n(0, x))
|
d.addCallback(lambda x: self.invite(0, u"Alice"))
|
||||||
d.addCallback(lambda x: self.join(0, alice_magic_dir, x))
|
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):
|
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(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))
|
d.addCallback(lambda x: self.check_config(0, alice_magic_dir))
|
||||||
def get_Alice_magicfolder(result):
|
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
|
return result
|
||||||
d.addCallback(get_Alice_magicfolder)
|
d.addCallback(get_Alice_magicfolder)
|
||||||
d.addCallback(lambda x: self.invite_n(0, u"Bob"))
|
d.addCallback(lambda x: self.invite(0, u"Bob"))
|
||||||
d.addCallback(lambda x: self.join(1, bob_magic_dir, x))
|
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):
|
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(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))
|
d.addCallback(lambda x: self.check_config(1, bob_magic_dir))
|
||||||
def get_Bob_magicfolder(result):
|
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
|
return result
|
||||||
d.addCallback(get_Bob_magicfolder)
|
d.addCallback(get_Bob_magicfolder)
|
||||||
|
def prepare_result(result):
|
||||||
def cleanup_Alice_and_Bob(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 = defer.succeed(None)
|
d.addCallback(prepare_result)
|
||||||
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
|
return d
|
||||||
|
|
||||||
class CreateMagicFolder(MagicFolderCLITestMixin, unittest.TestCase):
|
class CreateMagicFolder(MagicFolderCLITestMixin, unittest.TestCase):
|
||||||
|
@ -316,7 +316,20 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def test_alice_bob(self):
|
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):
|
class MockTest(MagicFolderTestMixin, unittest.TestCase):
|
||||||
"""This can run on any platform, and even if twisted.internet.inotify can't be imported."""
|
"""This can run on any platform, and even if twisted.internet.inotify can't be imported."""
|
||||||
|
Loading…
Reference in New Issue
Block a user