def testWithoutFileAndWithValidFile(self): # Two tests combined because first needed as init for the second file = self.folder.file('index.db') self.assertFalse(file.exists()) index = Index(file.path, self.layout) self.assertTrue(file.exists()) self.assertEqual(index.get_property('db_version'), DB_VERSION) index._db.close() del (index) index = Index(file.path, self.layout) self.assertTrue(file.exists()) self.assertEqual(index.get_property('db_version'), DB_VERSION)
def testWithBrokenFile(self): file = self.folder.file('index.db') file.write('this is not a database file...\n') self.assertTrue(file.exists()) with tests.LoggingFilter('zim.notebook.index', 'Overwriting'): with tests.LoggingFilter('zim.notebook.index', 'Could not access'): index = Index(file.path, self.layout) self.assertTrue(file.exists()) self.assertEqual(index.get_property('db_version'), DB_VERSION)
def testWithLockedFile(self): file = self.folder.file('index.db') file.write('this is not a database file...\n') os.chmod(file.path, 0o000) # make read-only self.addCleanup(lambda: os.chmod(file.path, 0o700)) self.assertTrue(file.exists()) with tests.LoggingFilter('zim.notebook.index', 'Overwriting'): with tests.LoggingFilter('zim.notebook.index', 'Could not access'): index = Index(file.path, self.layout) self.assertTrue(file.exists()) self.assertEqual(index.get_property('db_version'), DB_VERSION)
def testWithValidDBFile(self): # E.g. old index, not conforming our table layout file = self.folder.file('index.db') self.assertFalse(file.exists()) db = sqlite3.Connection(file.path) db.execute('CREATE TABLE zim_index (key TEXT);') db.close() self.assertTrue(file.exists()) index = Index(file.path, self.layout) self.assertTrue(file.exists()) self.assertEqual(index.get_property('db_version'), DB_VERSION)