def get_db(self): db = Database(database_override=':memory:') db._cursor.execute('CREATE TABLE media_parts(id, file)') db._cursor.executemany('INSERT INTO media_parts(id, file) VALUES (?, ?)', [(1, '/tests/fail'), (2, '/tests/fail'), (3, '/tests/fail')]) db.commit() return db
def test_update_database(self): with Database(database_override= './tests/database/com.plexapp.plugins.library.db') as db: m = Movie( 1, u"a", '/tests/b.avi', 2010, 2, 2.2, 'c', 1, './tests/posters/com.plexapp.agents.themoviedb_1a3b1b98c2799d759e110285001f536982cdb869', '/test') before = db._cursor.execute( 'SELECT file FROM media_parts WHERE id = ?', (m.mid, )).fetchone() cleaner.update_database(db, m) after = db._cursor.execute( 'SELECT file FROM media_parts WHERE id = ?', (m.mid, )).fetchone() self.assertNotEqual(before[0], after[0]) db.rollback()
def test_database_exception_rows(self): with self.assertRaises(PlexCleanerException) as e: db = Database(database_override='./tests/database/empty.db') db.get_rows() self.assertTrue('Unabled to fetch' in e.exception.message)
def test_database_exception_init(self): with self.assertRaises(PlexCleanerException) as e: db = Database(database_override='./tests/database/bad.db') db.get_rows() self.assertTrue('Could not open' in e.exception.message)
def test_get_rows(self): db = Database(database_override='./tests/database/com.plexapp.plugins.library.db') rows = db.get_rows().fetchall() self.assertEqual(len(rows), 98)
def test_database_exception(self): with self.assertRaises(PlexCleanerException) as e: db = Database(database_override='./path/to/com.plexapp.plugins.library.db') self.assertFalse(db.has_uncommited()) self.assertTrue('Could not connect' in e.exception.message)