def test_history_export2(self): if os.path.exists(DB_PATH): os.remove(DB_PATH) sqlstore = SQLStore(DB_PATH) lib = Library(sqlstore) h = History(sqlstore) h.setLogEnabled(True) h.setUpdateEnabled(True) lib.history = h uid = lib.insert(artist="artist1", album='album1', title='title1', path='/path') lib.incrementPlaycount(uid) records = list(h.export()) self.assertEqual(len(records), 1) record = records[0] self.assertEqual(record['uid'], uid) self.assertEqual(record['column'], Song.playtime)
def test_library_create(self): if os.path.exists(DB_PATH): os.remove(DB_PATH) sqlstore = SQLStore(DB_PATH) lib = Library(sqlstore) uid = lib.insert(artist="artist1", album='album1', title='title1', path='/path') song = lib.songFromId(uid) # check required fields self.assertEqual(song['artist'], 'artist1') self.assertEqual(song['album'], 'album1') self.assertEqual(song['title'], 'title1') self.assertEqual(song['path'], '/path') # check default fields self.assertEqual(song['playcount'], 0) # both these values should be 1 artists = list(lib.getArtists()) self.assertEqual(len(artists), 1) art = artists[0]['uid'] albums = list(lib.getAlbums(art)) self.assertEqual(len(albums), 1) lib.update(uid, artist="The Artist", album="Album", title="Title") song = lib.songFromId(uid) self.assertEqual(song['artist'], 'The Artist') self.assertEqual(song['album'], 'Album') self.assertEqual(song['title'], 'Title') lib.increment(uid, 'playcount', 5) song = lib.songFromId(uid) self.assertEqual(song['playcount'], 5) lib.increment(uid, 'playcount', -2) song = lib.songFromId(uid) self.assertEqual(song['playcount'], 3) # both these values should be 1, after updating artist,album artists = list(lib.getArtists()) self.assertEqual(len(artists), 1) art = artists[0]['uid'] albums = list(lib.getAlbums(art)) self.assertEqual(len(albums), 1)
def test_library_findpath(self): if os.path.exists(DB_PATH): os.remove(DB_PATH) sqlstore = SQLStore(DB_PATH) lib = Library(sqlstore) lib.insert(artist="artist1", album='album1', title='title1', path='C:\\path\\to\\file.mp3') lib.insert(artist="artist2", album='album2', title='title2', path='C:/path/to/file.mp3') lib.insert(artist="artist3", album='album3', title='title3', path='C:/file.mp3') # return the one file which is at the root directory res = list(lib.searchDirectory("C:\\", False)) self.assertEqual(len(res), 1) # show that the search result is a song dictionary self.assertEqual(res[0]['artist'], 'artist3') # return all songs, regardless of directory or toothpicks res = list(lib.searchDirectory("C:\\", True)) self.assertEqual(len(res), 3) # find a file that matches exactly res = list(lib.searchPath("C:\\file.mp3")) self.assertEqual(len(res), 1) pl = PlaylistManager(sqlstore).openPlaylist("current") pl.set([1, 2]) result = list(lib.searchPlaylist('current')) self.assertEqual(len(result), 2) result = list( lib.searchPlaylist('current', "art = art", invert=False, orderby="artist", reverse=True, limit=1)) self.assertEqual(result[0]['artist'], 'artist2') result = list(lib.searchPlaylist('current', invert=True)) self.assertEqual(result[0]['artist'], 'artist3') result = list(lib.searchPlaylist('current', "art = art", invert=True)) self.assertEqual(result[0]['artist'], 'artist3')
def test_library_delete(self): if os.path.exists(DB_PATH): os.remove(DB_PATH) sqlstore = SQLStore(DB_PATH) lib = Library(sqlstore) uid = lib.insert(artist="artist1", album='album1', title='title1', path='/path') lib.remove(uid) with self.assertRaises(KeyError): lib.songFromId(uid)
def test_history_import_playback(self): if os.path.exists(DB_PATH): os.remove(DB_PATH) sqlstore = SQLStore(DB_PATH) lib = Library(sqlstore) h = History(sqlstore) h.setLogEnabled(True) h.setUpdateEnabled(True) lib.history = h uid = lib.insert(artist="artist1", album='album1', title='title1', path='/path', last_played=100000) songb = lib.songFromId(uid) record = { 'date': 50000, 'uid': uid, 'column': Song.playtime, 'value': None } lib.import_record(record) songa = lib.songFromId(uid) self.assertEqual(songa[Song.last_played], songb[Song.last_played]) self.assertEqual(songa[Song.play_count], 1 + songb[Song.play_count]) new_date = 300000 record['date'] = new_date lib.import_record(record) songa = lib.songFromId(uid) self.assertNotEqual(songa[Song.frequency], 0) self.assertEqual(songa[Song.last_played], new_date) self.assertEqual(songa[Song.play_count], 2 + songb[Song.play_count])
def test_history_import_update_int(self): """ create a song, then a record which will update the rating import the record and verify that the artist name was changed successfully """ if os.path.exists(DB_PATH): os.remove(DB_PATH) sqlstore = SQLStore(DB_PATH) lib = Library(sqlstore) h = History(sqlstore) h.setLogEnabled(True) h.setUpdateEnabled(True) lib.history = h rate1 = 5 rate2 = 10 uid = lib.insert(artist="artist1", album='album1', title='title1', rating=rate1, path='/path') songb = lib.songFromId(uid) record = { 'date': 0, 'uid': uid, 'column': Song.rating, 'value': "%s" % rate2 } lib.import_record(record) songa = lib.songFromId(uid) self.assertNotEqual(songb[Song.rating], songa[Song.rating]) self.assertEqual(songa[Song.rating], rate2)