def open_db(self, db_url, bOpenOnly): """Function to open the specified SQLite database and store the Connection object in self.conn. If bOpenOnly is true, only opens the database. Otherwise uses brd.open_db(). """ if bOpenOnly: self.conn = sqlite3.connect(database=db_url, detect_types=sqlite3.PARSE_DECLTYPES) else: self.conn = brd.open_db( db_url )
def test_create_db(self): """Verifies that open_db() will create a new database with the proper table names. """ db_url = './test.db' # Make sure database doesn't exist. If it does, clobber it. if os.path.exists( db_url ): os.remove( db_url ) # Call open_db, which should create db and its tables self.conn = brd.open_db( db_url ) # Verify that file exists self.assertTrue( os.path.exists( db_url ) ) # Verify that files table exist self.assertTrue( self.find_table( self.table_names['files'] ) ) # Verify that dirs table exists self.assertTrue( self.find_table( self.table_names['dirs'] ) )
def test_new_fingerprint(self): """Tests new fingerprint file generation. """ # Call open_db, which should create db and its tables self.conn = brd.open_db( self.default_db ) # Close connection self.conn.close() # Verify that the fingerprint file does not already exist self.assertTrue( not os.path.exists( self.default_fp_file ) ) # Check the database os.system( self.script_name + ' checkdb' ) # Verify that the fingerprint file now exists self.assertTrue( os.path.exists( self.default_fp_file ) ) # Verify its contents expect_fp = self.calc_fingerprint( self.default_db ) with open( self.default_fp_file, 'rt' ) as f: got_fp = f.readline().rstrip(os.linesep) self.assertEqual( expect_fp, got_fp )