From: Daira Hopwood Date: Fri, 16 Oct 2015 19:39:39 +0000 (+0100) Subject: Test creation of a subdirectory. X-Git-Url: https://git.rkrishnan.org/(%5B%5E?a=commitdiff_plain;h=c178a647c8a23f3c0ddf6383422a410222cc1074;p=tahoe-lafs%2Ftahoe-lafs.git Test creation of a subdirectory. Signed-off-by: Daira Hopwood --- diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index 0d03e686..39a71ed1 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -5,6 +5,7 @@ from twisted.trial import unittest from twisted.internet import defer, task from allmydata.interfaces import IDirectoryNode +from allmydata.util.assertutil import precondition from allmydata.util import fake_inotify, fileutil from allmydata.util.deferredutil import DeferredListShouldSucceed @@ -257,8 +258,8 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual # Test that temporary files are not uploaded. d.addCallback(lambda ign: self._check_file(u"tempfile", "test", temporary=True)) - # Test that we tolerate creation of a subdirectory. - d.addCallback(lambda ign: os.mkdir(os.path.join(self.local_dir, u"directory"))) + # Test creation of a subdirectory. + d.addCallback(lambda ign: self._check_mkdir(u"directory")) # Write something longer, and also try to test a Unicode name if the fs can represent it. name_u = self.unicode_or_fallback(u"l\u00F8ng", u"long") @@ -270,7 +271,12 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual d.addBoth(self.cleanup) return d - def _check_file(self, name_u, data, temporary=False): + def _check_mkdir(self, name_u): + return self._check_file(name_u + u"/", "", directory=True) + + def _check_file(self, name_u, data, temporary=False, directory=False): + precondition(not (temporary and directory), temporary=temporary, directory=directory) + previously_uploaded = self._get_count('uploader.objects_succeeded') previously_disappeared = self._get_count('uploader.objects_disappeared') @@ -279,27 +285,34 @@ class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqual path_u = abspath_expanduser_unicode(name_u, base=self.local_dir) path = to_filepath(path_u) - # We don't use FilePath.setContent() here because it creates a temporary file that - # is renamed into place, which causes events that the test is not expecting. - f = open(path_u, "wb") - try: - if temporary and sys.platform != "win32": + if directory: + os.mkdir(path_u) + event_mask = self.inotify.IN_CREATE | self.inotify.IN_ISDIR + else: + # We don't use FilePath.setContent() here because it creates a temporary file that + # is renamed into place, which causes events that the test is not expecting. + f = open(path_u, "wb") + try: + if temporary and sys.platform != "win32": + os.unlink(path_u) + f.write(data) + finally: + f.close() + if temporary and sys.platform == "win32": os.unlink(path_u) - f.write(data) - finally: - f.close() - if temporary and sys.platform == "win32": - os.unlink(path_u) - self.notify(path, self.inotify.IN_DELETE) + self.notify(path, self.inotify.IN_DELETE) + event_mask = self.inotify.IN_CLOSE_WRITE + fileutil.flush_volume(path_u) - self.notify(path, self.inotify.IN_CLOSE_WRITE) + self.notify(path, event_mask) + encoded_name_u = magicpath.path2magic(name_u) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_failed'), 0)) if temporary: d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_disappeared'), previously_disappeared + 1)) else: - d.addCallback(lambda ign: self.upload_dirnode.get(name_u)) + d.addCallback(lambda ign: self.upload_dirnode.get(encoded_name_u)) d.addCallback(download_to_data) d.addCallback(lambda actual_data: self.failUnlessReallyEqual(actual_data, data)) d.addCallback(lambda ign: self.failUnlessReallyEqual(self._get_count('uploader.objects_succeeded'),