X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=src%2Fallmydata%2Ftest%2Ftest_magic_folder.py;h=00a872f8fcfdced2cea44cf7780b6ad8c2920104;hb=456f67f0a40272d2c6bab9d6645e921b0f9f691b;hp=d974e5debd8652ea61bd7481efc72575de5ef664;hpb=8a4692dcd5b090ca67953985d97c9e51208f8cc3;p=tahoe-lafs%2Ftahoe-lafs.git diff --git a/src/allmydata/test/test_magic_folder.py b/src/allmydata/test/test_magic_folder.py index d974e5de..00a872f8 100644 --- a/src/allmydata/test/test_magic_folder.py +++ b/src/allmydata/test/test_magic_folder.py @@ -20,10 +20,89 @@ from .test_cli_magic_folder import MagicFolderCLITestMixin from allmydata.frontends import magic_folder from allmydata.frontends.magic_folder import MagicFolder, Downloader, WriteFileMixin from allmydata import magicfolderdb, magicpath +from allmydata.util.fileutil import get_pathinfo from allmydata.util.fileutil import abspath_expanduser_unicode from allmydata.immutable.upload import Data +class MagicFolderDbTests(unittest.TestCase): + + def setUp(self): + self.temp = abspath_expanduser_unicode(unicode(self.mktemp())) + os.mkdir(self.temp) + dbfile = abspath_expanduser_unicode(u"testdb.sqlite", base=self.temp) + self.db = magicfolderdb.get_magicfolderdb(dbfile, create_version=(magicfolderdb.SCHEMA_v1, 1)) + self.failUnless(self.db, "unable to create magicfolderdb from %r" % (dbfile,)) + self.failUnlessEqual(self.db.VERSION, 1) + + def tearDown(self): + shutil.rmtree(self.temp) + + def test_create(self): + self.db.did_upload_version( + relpath_u=u'fake_path', + version=0, + last_uploaded_uri=None, + last_downloaded_uri='URI:foo', + last_downloaded_timestamp=1234.5, + pathinfo=get_pathinfo(self.temp), # a directory, but should be fine for test + ) + + entry = self.db.get_db_entry(u'fake_path') + self.assertTrue(entry is not None) + self.assertEqual(entry.last_downloaded_uri, 'URI:foo') + + def test_update(self): + self.db.did_upload_version( + relpath_u=u'fake_path', + version=0, + last_uploaded_uri=None, + last_downloaded_uri='URI:foo', + last_downloaded_timestamp=1234.5, + pathinfo=get_pathinfo(self.temp), # a directory, but should be fine for test + ) + self.db.did_upload_version( + relpath_u=u'fake_path', + version=1, + last_uploaded_uri=None, + last_downloaded_uri='URI:bar', + last_downloaded_timestamp=1234.5, + pathinfo=get_pathinfo(self.temp), # a directory, but should be fine for test + ) + + entry = self.db.get_db_entry(u'fake_path') + self.assertTrue(entry is not None) + self.assertEqual(entry.last_downloaded_uri, 'URI:bar') + self.assertEqual(entry.version, 1) + + def test_same_content_different_path(self): + content_uri = 'URI:CHK:27d2yruqwk6zb2w7hkbbfxxbue:ipmszjysmn4vdeaxz7rtxtv3gwv6vrqcg2ktrdmn4oxqqucltxxq:2:4:1052835840' + self.db.did_upload_version( + relpath_u=u'path0', + version=0, + last_uploaded_uri=None, + last_downloaded_uri=content_uri, + last_downloaded_timestamp=1234.5, + pathinfo=get_pathinfo(self.temp), # a directory, but should be fine for test + ) + self.db.did_upload_version( + relpath_u=u'path1', + version=0, + last_uploaded_uri=None, + last_downloaded_uri=content_uri, + last_downloaded_timestamp=1234.5, + pathinfo=get_pathinfo(self.temp), # a directory, but should be fine for test + ) + + entry = self.db.get_db_entry(u'path0') + self.assertTrue(entry is not None) + self.assertEqual(entry.last_downloaded_uri, content_uri) + + entry = self.db.get_db_entry(u'path1') + self.assertTrue(entry is not None) + self.assertEqual(entry.last_downloaded_uri, content_uri) + + class MagicFolderTestMixin(MagicFolderCLITestMixin, ShouldFailMixin, ReallyEqualMixin, NonASCIIPathMixin): """ These tests will be run both with a mock notifier, and (on platforms that support it)