def setUp(self): super(MediaTestCase, self).setUp() self.folder = Folder() self.folder.name = 'Root' self.folder.path = os.path.abspath('tests/assets') self.folder.root = True self.folder.has_cover_art = True # 420x420 PNG artist = Artist() artist.name = 'Artist' album = Album() album.artist = artist album.name = 'Album' self.track = Track() self.track.title = '23bytes' self.track.number = 1 self.track.disc = 1 self.track.artist = artist self.track.album = album self.track.path = os.path.abspath('tests/assets/23bytes') self.track.root_folder = self.folder self.track.folder = self.folder self.track.duration = 2 self.track.bitrate = 320 self.track.content_type = 'audio/mpeg' self.track.last_modification = 0 self.store.add(self.track) self.store.commit()
def setUp(self): super(PlaylistTestCase, self).setUp() root = Folder() root.root = True root.name = 'Root folder' root.path = 'tests/assets' self.store.add(root) artist = Artist() artist.name = 'Artist' album = Album() album.name = 'Album' album.artist = artist songs = {} for num, song in enumerate([ 'One', 'Two', 'Three', 'Four' ]): track = Track() track.disc = 1 track.number = num track.title = song track.duration = 2 track.album = album track.artist = artist track.bitrate = 320 track.path = 'tests/assets/empty' track.content_type = 'audio/mpeg' track.last_modification = 0 track.root_folder = root track.folder = root self.store.add(track) songs[song] = track users = { u.name: u for u in self.store.find(User) } playlist = Playlist() playlist.user = users['alice'] playlist.name = "Alice's" playlist.add(songs['One']) playlist.add(songs['Three']) self.store.add(playlist) playlist = Playlist() playlist.user = users['alice'] playlist.public = True playlist.name = "Alice's public" playlist.add(songs['One']) playlist.add(songs['Two']) self.store.add(playlist) playlist = Playlist() playlist.user = users['bob'] playlist.name = "Bob's" playlist.add(songs['Two']) playlist.add(songs['Four']) self.store.add(playlist) self.store.commit()
def setUp(self): super(BrowseTestCase, self).setUp() empty = Folder() empty.root = True empty.name = 'Empty root' empty.path = '/tmp' self.store.add(empty) root = Folder() root.root = True root.name = 'Root folder' root.path = 'tests/assets' self.store.add(root) for letter in 'ABC': folder = Folder() folder.name = letter + 'rtist' folder.path = 'tests/assets/{}rtist'.format(letter) folder.parent = root artist = Artist() artist.name = letter + 'rtist' for lether in 'AB': afolder = Folder() afolder.name = letter + lether + 'lbum' afolder.path = 'tests/assets/{0}rtist/{0}{1}lbum'.format(letter, lether) afolder.parent = folder album = Album() album.name = letter + lether + 'lbum' album.artist = artist for num, song in enumerate([ 'One', 'Two', 'Three' ]): track = Track() track.disc = 1 track.number = num track.title = song track.duration = 2 track.album = album track.artist = artist track.bitrate = 320 track.path = 'tests/assets/{0}rtist/{0}{1}lbum/{2}'.format(letter, lether, song) track.content_type = 'audio/mpeg' track.last_modification = 0 track.root_folder = root track.folder = afolder self.store.add(track) self.store.commit() self.assertEqual(self.store.find(Folder).count(), 11) self.assertEqual(self.store.find(Folder, Folder.root == True).count(), 2) self.assertEqual(self.store.find(Artist).count(), 3) self.assertEqual(self.store.find(Album).count(), 6) self.assertEqual(self.store.find(Track).count(), 18)
def __find_artist(self, artist): ar = self.__store.find(Artist, Artist.name == artist).one() if ar: return ar ar = Artist() ar.name = artist self.__store.add(ar) self.__added_artists += 1 return ar
def setUp(self): super(PlaylistTestCase, self).setUp() folder = Folder() folder.name = 'Root' folder.path = 'tests/assets' folder.root = True artist = Artist() artist.name = 'Artist!' album = Album() album.name = 'Album!' album.artist = artist track = Track() track.path = 'tests/assets/23bytes' track.title = '23bytes' track.artist = artist track.album = album track.folder = folder track.root_folder = folder track.duration = 2 track.disc = 1 track.number = 1 track.content_type = 'audio/mpeg' track.bitrate = 320 track.last_modification = 0 playlist = Playlist() playlist.name = 'Playlist!' playlist.user = self.store.find(User, User.name == 'alice').one() for _ in range(4): playlist.add(track) self.store.add(track) self.store.add(playlist) self.store.commit() self.playlist = playlist
def test_change(self): path = self._addfile() self._sleep() trackid = None with db_session: self.assertEqual(Track.select().count(), 1) self.assertEqual( Artist.select(lambda a: a.name == "Some artist").count(), 1) trackid = Track.select().first().id tags = mutagen.File(path, easy=True) tags["artist"] = "Renamed" tags.save() self._sleep() with db_session: self.assertEqual(Track.select().count(), 1) self.assertEqual( Artist.select(lambda a: a.name == "Some artist").count(), 0) self.assertEqual( Artist.select(lambda a: a.name == "Renamed").count(), 1) self.assertEqual(Track.select().first().id, trackid)
def setUp(self): super().setUp() with db_session: folder = Folder( name="Root", path=os.path.abspath("tests/assets"), root=True, cover_art="cover.jpg", ) folder = Folder.get(name="Root") self.folderid = folder.id artist = Artist(name="Artist") album = Album(artist=artist, name="Album") track = Track( title="23bytes", number=1, disc=1, artist=artist, album=album, path=os.path.abspath("tests/assets/23bytes"), root_folder=folder, folder=folder, duration=2, bitrate=320, last_modification=0, ) self.trackid = track.id self.formats = ["mp3", "flac", "ogg", "m4a"] for i in range(len(self.formats)): track_embeded_art = Track( title="[silence]", number=1, disc=1, artist=artist, album=album, path=os.path.abspath( "tests/assets/formats/silence.{}".format( self.formats[i])), root_folder=folder, folder=folder, duration=2, bitrate=320, last_modification=0, ) self.formats[i] = track_embeded_art.id
def test_get_artist(self): # dataset should be improved to have tracks by a different artist than the album's artist self._make_request('getArtist', error = 10) self._make_request('getArtist', { 'id': 'artist' }, error = 0) self._make_request('getArtist', { 'id': str(uuid.uuid4()) }, error = 70) with db_session: for ar in Artist.select(): rv, child = self._make_request('getArtist', { 'id': str(ar.id) }, tag = 'artist') self.assertEqual(child.get('id'), str(ar.id)) self.assertEqual(child.get('albumCount'), str(len(child))) self.assertEqual(len(child), ar.albums.count()) for dal, xal in zip(sorted(ar.albums, key = lambda a: a.name), sorted(child, key = lambda c: c.get('name'))): self.assertEqual(dal.name, xal.get('name')) self.assertEqual(xal.get('artist'), ar.name) # could break with a better dataset self.assertEqual(xal.get('artistId'), str(ar.id)) # see above
def setUp(self): super(BrowseTestCase, self).setUp() with db_session: Folder(root = True, name = 'Empty root', path = '/tmp') root = Folder(root = True, name = 'Root folder', path = 'tests/assets') for letter in 'ABC': folder = Folder( name = letter + 'rtist', path = 'tests/assets/{}rtist'.format(letter), parent = root ) artist = Artist(name = letter + 'rtist') for lether in 'AB': afolder = Folder( name = letter + lether + 'lbum', path = 'tests/assets/{0}rtist/{0}{1}lbum'.format(letter, lether), parent = folder ) album = Album(name = letter + lether + 'lbum', artist = artist) for num, song in enumerate([ 'One', 'Two', 'Three' ]): track = Track( disc = 1, number = num, title = song, duration = 2, album = album, artist = artist, bitrate = 320, path = 'tests/assets/{0}rtist/{0}{1}lbum/{2}'.format(letter, lether, song), content_type = 'audio/mpeg', last_modification = 0, root_folder = root, folder = afolder ) self.assertEqual(Folder.select().count(), 11) self.assertEqual(Folder.select(lambda f: f.root).count(), 2) self.assertEqual(Artist.select().count(), 3) self.assertEqual(Album.select().count(), 6) self.assertEqual(Track.select().count(), 18)
def setUp(self): super(MediaTestCase, self).setUp() with db_session: folder = Folder(name='Root', path=os.path.abspath('tests/assets'), root=True, cover_art='cover.jpg') self.folderid = folder.id artist = Artist(name='Artist') album = Album(artist=artist, name='Album') track = Track(title='23bytes', number=1, disc=1, artist=artist, album=album, path=os.path.abspath('tests/assets/23bytes'), root_folder=folder, folder=folder, duration=2, bitrate=320, content_type='audio/mpeg', last_modification=0) self.trackid = track.id self.formats = [('mp3', 'mpeg'), ('flac', 'flac'), ('ogg', 'ogg')] for i in range(len(self.formats)): track_embeded_art = Track( title='[silence]', number=1, disc=1, artist=artist, album=album, path=os.path.abspath( 'tests/assets/formats/silence.{0}'.format( self.formats[i][0])), root_folder=folder, folder=folder, duration=2, bitrate=320, content_type='audio/{0}'.format(self.formats[i][1]), last_modification=0) self.formats[i] = track_embeded_art.id
def setUp(self): super(AlbumSongsTestCase, self).setUp() with db_session: folder = Folder(name='Root', root=True, path='tests/assets') artist = Artist(name='Artist') album = Album(name='Album', artist=artist) track = Track(title='Track', album=album, artist=artist, disc=1, number=1, path='tests/assets/empty', folder=folder, root_folder=folder, duration=2, bitrate=320, last_modification=0)
def setUp(self): super(AlbumSongsTestCase, self).setUp() with db_session: folder = Folder(name="Root", root=True, path="tests/assets") artist = Artist(name="Artist") album = Album(name="Album", artist=artist) track = Track( title="Track", album=album, artist=artist, disc=1, number=1, path="tests/assets/empty", folder=folder, root_folder=folder, duration=2, bitrate=320, last_modification=0, )
def setUp(self): super(PlaylistTestCase, self).setUp() with db_session: root = Folder(root=True, name="Root folder", path="tests/assets") artist = Artist(name="Artist") album = Album(name="Album", artist=artist) songs = {} for num, song in enumerate(["One", "Two", "Three", "Four"]): track = Track( disc=1, number=num, title=song, duration=2, album=album, artist=artist, bitrate=320, path="tests/assets/" + song, last_modification=0, root_folder=root, folder=root, ) songs[song] = track users = {u.name: u for u in User.select()} playlist = Playlist(user=users["alice"], name="Alice's") playlist.add(songs["One"]) playlist.add(songs["Three"]) playlist = Playlist(user=users["alice"], public=True, name="Alice's public") playlist.add(songs["One"]) playlist.add(songs["Two"]) playlist = Playlist(user=users["bob"], name="Bob's") playlist.add(songs["Two"]) playlist.add(songs["Four"])
def setUp(self): super().setUp() with db_session: folder = Folder( name="Root", path=os.path.abspath("tests/assets/lyrics"), root=True, ) artist = Artist(name="Artist") album = Album(artist=artist, name="Album") Track( title="Nope", number=1, disc=1, artist=artist, album=album, path=os.path.abspath("tests/assets/lyrics/empty.mp3"), root_folder=folder, folder=folder, duration=2, bitrate=320, last_modification=0, ) Track( title="Yay", number=1, disc=1, artist=artist, album=album, path=os.path.abspath("tests/assets/lyrics/withlyrics.mp3"), root_folder=folder, folder=folder, duration=2, bitrate=320, last_modification=0, )
def setUp(self): super(PlaylistTestCase, self).setUp() with db_session: root = Folder(root = True, name = 'Root folder', path = 'tests/assets') artist = Artist(name = 'Artist') album = Album(name = 'Album', artist = artist) songs = {} for num, song in enumerate([ 'One', 'Two', 'Three', 'Four' ]): track = Track( disc = 1, number = num, title = song, duration = 2, album = album, artist = artist, bitrate = 320, path = 'tests/assets/' + song, content_type = 'audio/mpeg', last_modification = 0, root_folder = root, folder = root ) songs[song] = track users = { u.name: u for u in User.select() } playlist = Playlist(user = users['alice'], name = "Alice's") playlist.add(songs['One']) playlist.add(songs['Three']) playlist = Playlist(user = users['alice'], public = True, name = "Alice's public") playlist.add(songs['One']) playlist.add(songs['Two']) playlist = Playlist(user = users['bob'], name = "Bob's") playlist.add(songs['Two']) playlist.add(songs['Four'])
def setUp(self): super().setUp() with db_session: folder = Folder(name="Root", root=True, path="tests/assets") artist = Artist(name="Artist") album = Album(name="Album", artist=artist) Track( title="Track 1", album=album, artist=artist, disc=1, number=1, year=123, path="tests/assets/folder/1", folder=folder, root_folder=folder, duration=2, bitrate=320, last_modification=0, ) Track( title="Track 2", album=album, artist=artist, disc=1, number=1, year=124, genre="Lampshade", path="tests/assets/folder/2", folder=folder, root_folder=folder, duration=2, bitrate=320, last_modification=0, )