From 456f67f0a40272d2c6bab9d6645e921b0f9f691b Mon Sep 17 00:00:00 2001 From: meejah Date: Mon, 18 Jan 2016 08:39:36 -0700 Subject: [PATCH] Add some magicfolder database tests --- src/allmydata/test/test_magic_folder.py | 79 +++++++++++++++++++++++++ 1 file changed, 79 insertions(+) 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) -- 2.45.2