From: David Stainton Date: Fri, 26 Jun 2015 19:14:14 +0000 (-0700) Subject: Add test to list remote collective dir X-Git-Url: https://git.rkrishnan.org/pf/content/it.html?a=commitdiff_plain;h=5996fa53ec884feb05a1d1b5610cf906481eca56;p=tahoe-lafs%2Ftahoe-lafs.git Add test to list remote collective dir here you can see that i've avoided tampering with many of our unit tests by making collective_dirnode conditional. instead perhaps our unit tests should fail if collective_cap is blank. --- diff --git a/src/allmydata/frontends/magic_folder.py b/src/allmydata/frontends/magic_folder.py index 85cdd04f..4827b245 100644 --- a/src/allmydata/frontends/magic_folder.py +++ b/src/allmydata/frontends/magic_folder.py @@ -71,6 +71,14 @@ class MagicFolder(service.MultiService): # TODO: allow a path rather than a cap URI. self._upload_dirnode = self._client.create_node_from_uri(upload_dircap) + if collective_dircap != "": + # XXX this condition used for some unit tests + self._collective_dirnode = self._client.create_node_from_uri(collective_dircap) + if not IDirectoryNode.providedBy(self._collective_dirnode): + raise AssertionError("The URI in 'private/collective_dircap' does not refer to a directory.") + if self._collective_dirnode.is_unknown() or not self._collective_dirnode.is_readonly(): + raise AssertionError("The URI in 'private/collective_dircap' is not a readonly cap to a directory.") + if not IDirectoryNode.providedBy(self._upload_dirnode): raise AssertionError("The URI in 'private/magic_folder_dircap' does not refer to a directory.") if self._upload_dirnode.is_unknown() or self._upload_dirnode.is_readonly(): @@ -98,6 +106,9 @@ class MagicFolder(service.MultiService): self._notifier.watch(self._local_path, mask=self.mask, callbacks=[self._notify], recursive=True) + def _scan_remote_collective(self): + return self._collective_dirnode.list() + def _db_file_is_uploaded(self, childpath): """_db_file_is_uploaded returns true if the file was previously uploaded """ diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index c746b230..c809e8ad 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -52,7 +52,7 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual self.failUnless(IDirectoryNode.providedBy(n)) self.upload_dirnode = n self.upload_dircap = n.get_uri() - self.collective_dircap = "abc123" + self.collective_dircap = "" def _create_magicfolder(self, ign): dbfile = abspath_expanduser_unicode(u"magicfolderdb.sqlite", base=self.basedir) @@ -321,6 +321,22 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('magic_folder.objects_queued'), 0)) return d + def test_remote_scan(self): + self.set_up_grid() + self.local_dir = abspath_expanduser_unicode(self.unicode_or_fallback(u"l\u00F8cal_dir", u"local_dir"), + base=self.basedir) + self.mkdir_nonascii(self.local_dir) + self.client = self.g.clients[0] + self.stats_provider = self.client.stats_provider + d = self.create_invite_join_magic_folder(u"Alice", self.local_dir) + d.addCallback(self._create_magicfolder) + d.addCallback(lambda x: self.magicfolder._scan_remote_collective()) + def display_list(results): + print "LIST ", results + d.addCallback(display_list) + d.addBoth(self._cleanup) + return d + class MockTest(MagicFolderTestMixin, unittest.TestCase): """This can run on any platform, and even if twisted.internet.inotify can't be imported."""