def test_delete(self): folder = Folder() folder.name = 'folder' folder.path = 'tests/assets' folder.root = True self.store.add(folder) self.store.commit() self._login('bob', 'B0b') rv = self.client.get('/folder/del/' + str(folder.id), follow_redirects=True) self.assertIn('There\'s nothing much to see', rv.data) self.assertEqual(self.store.find(Folder).count(), 1) self._logout() self._login('alice', 'Alic3') rv = self.client.get('/folder/del/string', follow_redirects=True) self.assertIn('Invalid', rv.data) rv = self.client.get('/folder/del/' + str(uuid.uuid4()), follow_redirects=True) self.assertIn('No such folder', rv.data) rv = self.client.get('/folder/del/' + str(folder.id), follow_redirects=True) self.assertIn('Music folders', rv.data) self.assertEqual(self.store.find(Folder).count(), 0)
def setUp(self): super(AnnotationTestCase, self).setUp() with db_session: root = Folder(name='Root', root=True, path='tests') folder = Folder(name='Folder', path='tests/assets', parent=root) 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=root, duration=2, bitrate=320, content_type='audio/mpeg', last_modification=0) self.folderid = folder.id self.artistid = artist.id self.albumid = album.id self.trackid = track.id self.user = User.get(name='alice')
def setUp(self): super(AlbumSongsTestCase, self).setUp() folder = Folder() folder.name = 'Root' folder.root = True folder.path = 'tests/assets' artist = Artist() artist.name = 'Artist' album = Album() album.name = 'Album' album.artist = artist track = Track() track.title = 'Track' track.album = album track.artist = artist track.disc = 1 track.number = 1 track.path = 'tests/assets/empty' track.folder = folder track.root_folder = folder track.duration = 2 track.bitrate = 320 track.content_type = 'audio/mpeg' track.last_modification = 0 self.store.add(track) self.store.commit()
def test_get_album_list(self): self._make_request("getAlbumList", error=10) self._make_request("getAlbumList", {"type": "kraken"}, error=0) self._make_request("getAlbumList", {"type": "random", "size": "huge"}, error=0) self._make_request( "getAlbumList", {"type": "newest", "offset": "minus one"}, error=0 ) types = [ "random", "newest", "highest", "frequent", "recent", "alphabeticalByName", "alphabeticalByArtist", "starred", ] for t in types: self._make_request( "getAlbumList", {"type": t}, tag="albumList", skip_post=True ) rv, child = self._make_request( "getAlbumList", {"type": "random"}, tag="albumList", skip_post=True ) with db_session: Folder.get().delete() rv, child = self._make_request( "getAlbumList", {"type": "random"}, tag="albumList" ) self.assertEqual(len(child), 0)
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 __find_folder(self, path): path = os.path.dirname(path) folders = self.__store.find(Folder, Folder.path == path) count = folders.count() if count > 1: raise Exception("Found multiple folders for '{}'.".format(path)) elif count == 1: return folders.one() folder = self.__store.find(Folder, Like(path, SQL("folder.path||'%'"))).order_by(Folder.path).last() full_path = folder.path path = path[len(folder.path) + 1:] for name in path.split(os.sep): full_path = os.path.join(full_path, name) fold = Folder() fold.root = False fold.name = name fold.path = full_path fold.parent = folder self.__store.add(fold) folder = fold return folder
def test_get_album_list(self): self._make_request('getAlbumList', error=10) self._make_request('getAlbumList', {'type': 'kraken'}, error=0) self._make_request('getAlbumList', { 'type': 'random', 'size': 'huge' }, error=0) self._make_request('getAlbumList', { 'type': 'newest', 'offset': 'minus one' }, error=0) types = [ 'random', 'newest', 'highest', 'frequent', 'recent', 'alphabeticalByName', 'alphabeticalByArtist', 'starred' ] for t in types: self._make_request('getAlbumList', {'type': t}, tag='albumList', skip_post=True) rv, child = self._make_request('getAlbumList', {'type': 'random'}, tag='albumList', skip_post=True) with db_session: Folder.get().delete() rv, child = self._make_request('getAlbumList', {'type': 'random'}, tag='albumList') self.assertEqual(len(child), 0)
def add(store, name, path): if not store.find(Folder, Folder.name == name, Folder.root == True).is_empty(): return FolderManager.NAME_EXISTS path = unicode(os.path.abspath(path)) if not os.path.isdir(path): return FolderManager.INVALID_PATH if not store.find(Folder, Folder.path == path).is_empty(): return FolderManager.PATH_EXISTS if any( path.startswith(p) for p in store.find(Folder).values(Folder.path)): return FolderManager.PATH_EXISTS if not store.find(Folder, Folder.path.startswith(path)).is_empty(): return FolderManager.SUBPATH_EXISTS folder = Folder() folder.root = True folder.name = name folder.path = path store.add(folder) store.commit() return FolderManager.SUCCESS
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 __find_folder(self, path): path = os.path.dirname(path) folders = self.__store.find(Folder, Folder.path == path) count = folders.count() if count > 1: raise Exception("Found multiple folders for '{}'.".format(path)) elif count == 1: return folders.one() db = self.__store.get_database().__module__[len('storm.databases.'):] folder = self.__store.find(Folder, Like(path, Concat(Folder.path, os.sep + u'%', db))).order_by(Folder.path).last() full_path = folder.path path = path[len(folder.path) + 1:] for name in path.split(os.sep): full_path = os.path.join(full_path, name) fold = Folder() fold.root = False fold.name = name fold.path = full_path fold.parent = folder self.__store.add(fold) folder = fold return folder
def setUp(self): super().setUp() with db_session: root = Folder(name="Root", root=True, path="tests") folder = Folder(name="Folder", path="tests/assets", parent=root) artist = Artist(name="Artist") album = Album(name="Album", artist=artist) # Populate folder ids root = Folder.get(name="Root") folder = Folder.get(name="Folder") track = Track( title="Track", album=album, artist=artist, disc=1, number=1, path="tests/assets/empty", folder=folder, root_folder=root, duration=2, bitrate=320, last_modification=0, ) self.folderid = folder.id self.artistid = artist.id self.albumid = album.id self.trackid = track.id self.user = User.get(name="alice")
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_add_post(self): self._login("alice", "Alic3") rv = self.client.post("/folder/add") self.assertIn("required", rv.data) rv = self.client.post("/folder/add", data={"name": "name"}) self.assertIn("required", rv.data) rv = self.client.post("/folder/add", data={"path": "path"}) self.assertIn("required", rv.data) rv = self.client.post("/folder/add", data={ "name": "name", "path": "path" }) self.assertIn("Add Folder", rv.data) rv = self.client.post( "/folder/add", data={ "name": "name", "path": "tests/assets" }, follow_redirects=True, ) self.assertIn("created", rv.data) with db_session: self.assertEqual(Folder.select().count(), 1)
def test_get_music_directory(self): self._make_request('getMusicDirectory', error=10) self._make_request('getMusicDirectory', {'id': 'id'}, error=0) self._make_request('getMusicDirectory', {'id': str(uuid.uuid4())}, error=70) # should test with folders with both children folders and tracks. this code would break in that case with db_session: for f in Folder.select(): rv, child = self._make_request('getMusicDirectory', {'id': str(f.id)}, tag='directory') self.assertEqual(child.get('id'), str(f.id)) self.assertEqual(child.get('name'), f.name) self.assertEqual(len(child), f.children.count() + f.tracks.count()) for dbc, xmlc in zip( sorted(f.children, key=lambda c: c.name), sorted(child, key=lambda c: c.get('title'))): self.assertEqual(dbc.name, xmlc.get('title')) self.assertEqual(xmlc.get('artist'), f.name) self.assertEqual(xmlc.get('parent'), str(f.id)) for t, xmlc in zip(sorted(f.tracks, key=lambda t: t.title), sorted(child, key=lambda c: c.get('title'))): self.assertEqual(t.title, xmlc.get('title')) self.assertEqual(xmlc.get('parent'), str(f.id))
def setUp(self): super(PlaylistTestCase, self).setUp() with db_session: folder = Folder(name="Root", path="tests/assets", root=True) artist = Artist(name="Artist!") album = Album(name="Album!", artist=artist) track = Track( path="tests/assets/23bytes", title="23bytes", artist=artist, album=album, folder=folder, root_folder=folder, duration=2, disc=1, number=1, bitrate=320, last_modification=0, ) playlist = Playlist(name="Playlist!", user=User.get(name="alice")) for _ in range(4): playlist.add(track) self.playlistid = playlist.id
def setUp(self): super().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( 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, )
def test_get_music_directory(self): self._make_request("getMusicDirectory", error=10) self._make_request("getMusicDirectory", {"id": "id"}, error=0) self._make_request("getMusicDirectory", {"id": 1234567890}, error=70) # should test with folders with both children folders and tracks. this code would break in that case with db_session: for f in Folder.select(): rv, child = self._make_request("getMusicDirectory", {"id": str(f.id)}, tag="directory") self.assertEqual(child.get("id"), str(f.id)) self.assertEqual(child.get("name"), f.name) self.assertEqual(len(child), f.children.count() + f.tracks.count()) for dbc, xmlc in zip( sorted(f.children, key=lambda c: c.name), sorted(child, key=lambda c: c.get("title")), ): self.assertEqual(dbc.name, xmlc.get("title")) self.assertEqual(xmlc.get("artist"), f.name) self.assertEqual(xmlc.get("parent"), str(f.id)) for t, xmlc in zip( sorted(f.tracks, key=lambda t: t.title), sorted(child, key=lambda c: c.get("title")), ): self.assertEqual(t.title, xmlc.get("title")) self.assertEqual(xmlc.get("parent"), str(f.id))
def test_get_random_songs(self): self._make_request("getRandomSongs", {"size": "8 floors"}, error=0) self._make_request("getRandomSongs", {"fromYear": "year"}, error=0) self._make_request("getRandomSongs", {"toYear": "year"}, error=0) self._make_request("getRandomSongs", {"musicFolderId": "idid"}, error=0) self._make_request("getRandomSongs", {"musicFolderId": 1234567890}, error=70) rv, child = self._make_request("getRandomSongs", tag="randomSongs", skip_post=True) with db_session: fid = Folder.get().id self._make_request( "getRandomSongs", { "fromYear": -52, "toYear": "1984", "genre": "some cryptic subgenre youve never heard of", "musicFolderId": fid, }, tag="randomSongs", )
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
def test_get_indexes(self): self._make_request("getIndexes", {"musicFolderId": "abcdef"}, error=0) self._make_request("getIndexes", {"musicFolderId": 1234567890}, error=70) self._make_request("getIndexes", {"ifModifiedSince": "quoi"}, error=0) rv, child = self._make_request( "getIndexes", {"ifModifiedSince": int(time.time() * 1000 + 1000)}, tag="indexes", ) self.assertEqual(len(child), 0) with db_session: fid = Folder.get(name="Empty root").id rv, child = self._make_request("getIndexes", {"musicFolderId": str(fid)}, tag="indexes") self.assertEqual(len(child), 0) rv, child = self._make_request("getIndexes", tag="indexes") self.assertEqual(len(child), 3) for i, letter in enumerate(["A", "B", "C"]): self.assertEqual(child[i].get("name"), letter) self.assertEqual(len(child[i]), 1) self.assertEqual(child[i][0].get("name"), letter + "rtist")
def test_add_cover_then_file(self): path = self._addcover() self._addfile() self._sleep() with db_session: self.assertEqual(Folder.select().first().cover_art, os.path.basename(path))
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().setUp() with db_session: 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( 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), last_modification=0, root_folder=root, folder=afolder, ) commit() self.assertEqual(Folder.select().count(), 10) self.assertEqual(Artist.select().count(), 3) self.assertEqual(Album.select().count(), 6) self.assertEqual(Track.select().count(), 18)
def test_folder_delete(self): with tempfile.TemporaryDirectory() as d: self.__add_folder("tmpfolder", d) self.__invoke("folder delete randomfolder", True) self.__invoke("folder delete tmpfolder") with db_session: self.assertEqual(Folder.select().count(), 0)
def test_folder_add(self): with tempfile.TemporaryDirectory() as d: self.__add_folder("tmpfolder", d) with db_session: f = Folder.select().first() self.assertIsNotNone(f) self.assertEqual(f.path, d)
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 test_naming_add_bad(self): good = os.path.basename(self._addcover("cover")) self._sleep() self._addcover() self._sleep() with db_session: self.assertEqual(Folder.select().first().cover_art, good)
def test_get_album_list(self): self._make_request('getAlbumList', error = 10) self._make_request('getAlbumList', { 'type': 'kraken' }, error = 0) self._make_request('getAlbumList', { 'type': 'random', 'size': 'huge' }, error = 0) self._make_request('getAlbumList', { 'type': 'newest', 'offset': 'minus one' }, error = 0) types = [ 'random', 'newest', 'highest', 'frequent', 'recent', 'alphabeticalByName', 'alphabeticalByArtist', 'starred' ] for t in types: self._make_request('getAlbumList', { 'type': t }, tag = 'albumList', skip_post = True) rv, child = self._make_request('getAlbumList', { 'type': 'random' }, tag = 'albumList', skip_post = True) with db_session: Folder.get().delete() rv, child = self._make_request('getAlbumList', { 'type': 'random' }, tag = 'albumList') self.assertEqual(len(child), 0)
def test_folder_delete(self): with self._tempdir() as d: self.__cli.onecmd("folder add tmpfolder " + d) self.__cli.onecmd("folder delete randomfolder") self.__cli.onecmd("folder delete tmpfolder") with db_session: self.assertEqual(Folder.select().count(), 0)
def test_folder_add(self): with self._tempdir() as d: self.__cli.onecmd("folder add tmpfolder " + d) with db_session: f = Folder.select().first() self.assertIsNotNone(f) self.assertEqual(f.path, d)
def setUp(self): super().setUp(apiVersion="1.16.0") with db_session: Folder(name="Root", root=True, path="tests/assets") self._daemon = Daemon(self.config) self._thread = Thread(target=self._daemon.run) self._thread.start()
def test_naming_remove_bad(self): bad = self._addcover() good = self._addcover("cover") self._sleep() os.unlink(bad) self._sleep() with db_session: self.assertEqual(Folder.select().first().cover_art, os.path.basename(good))
def test_folder_add_errors(self): with self._tempdir() as d: self.__cli.onecmd("folder add f1 " + d) self.__cli.onecmd("folder add f2 " + d) with self._tempdir() as d: self.__cli.onecmd("folder add f1 " + d) self.__cli.onecmd("folder add f3 /invalid/path") with db_session: self.assertEqual(Folder.select().count(), 1)
def test_remove_cover(self): self._addfile() path = self._addcover() self._sleep() os.unlink(path) self._sleep() with db_session: self.assertIsNone(Folder.select().first().cover_art)
def add(store, name, path): if not store.find(Folder, Folder.name == name, Folder.root == True).is_empty(): return FolderManager.NAME_EXISTS path = os.path.abspath(path) if not os.path.isdir(path): return FolderManager.INVALID_PATH if not store.find(Folder, Folder.path == path).is_empty(): return FolderManager.PATH_EXISTS folder = Folder() folder.root = True folder.name = name folder.path = path store.add(folder) store.commit() return FolderManager.SUCCESS
def test_scan(self): folder = Folder() folder.name = 'folder' folder.path = 'tests/assets' folder.root = True self.store.add(folder) self.store.commit() self._login('alice', 'Alic3') rv = self.client.get('/folder/scan/string', follow_redirects = True) self.assertIn('Invalid', rv.data) rv = self.client.get('/folder/scan/' + str(uuid.uuid4()), follow_redirects = True) self.assertIn('No such folder', rv.data) rv = self.client.get('/folder/scan/' + str(folder.id), follow_redirects = True) self.assertIn('Added', rv.data) self.assertIn('Deleted', rv.data) rv = self.client.get('/folder/scan', follow_redirects = True) self.assertIn('Added', rv.data) self.assertIn('Deleted', rv.data)
def test_rename(self): path = self._addcover() self._sleep() newpath = self._temppath(".jpg") shutil.move(path, newpath) self._sleep() with db_session: self.assertEqual(Folder.select().first().cover_art, os.path.basename(newpath))
def test_get_random_songs(self): self._make_request('getRandomSongs', { 'size': '8 floors' }, error = 0) self._make_request('getRandomSongs', { 'fromYear': 'year' }, error = 0) self._make_request('getRandomSongs', { 'toYear': 'year' }, error = 0) self._make_request('getRandomSongs', { 'musicFolderId': 'idid' }, error = 0) self._make_request('getRandomSongs', { 'musicFolderId': uuid.uuid4() }, error = 70) rv, child = self._make_request('getRandomSongs', tag = 'randomSongs', skip_post = True) with db_session: fid = Folder.get().id self._make_request('getRandomSongs', { 'fromYear': -52, 'toYear': '1984', 'genre': 'some cryptic subgenre youve never heard of', 'musicFolderId': fid }, tag = 'randomSongs')
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_delete(self): folder = Folder() folder.name = 'folder' folder.path = 'tests/assets' folder.root = True self.store.add(folder) self.store.commit() self._login('bob', 'B0b') rv = self.client.get('/folder/del/' + str(folder.id), follow_redirects = True) self.assertIn('There\'s nothing much to see', rv.data) self.assertEqual(self.store.find(Folder).count(), 1) self._logout() self._login('alice', 'Alic3') rv = self.client.get('/folder/del/string', follow_redirects = True) self.assertIn('Invalid', rv.data) rv = self.client.get('/folder/del/' + str(uuid.uuid4()), follow_redirects = True) self.assertIn('No such folder', rv.data) rv = self.client.get('/folder/del/' + str(folder.id), follow_redirects = True) self.assertIn('Music folders', rv.data) self.assertEqual(self.store.find(Folder).count(), 0)
def add(store, name, path): if not store.find(Folder, Folder.name == name, Folder.root == True).is_empty(): return FolderManager.NAME_EXISTS path = unicode(os.path.abspath(path)) if not os.path.isdir(path): return FolderManager.INVALID_PATH if not store.find(Folder, Folder.path == path).is_empty(): return FolderManager.PATH_EXISTS if any(path.startswith(p) for p in store.find(Folder).values(Folder.path)): return FolderManager.PATH_EXISTS if not store.find(Folder, Folder.path.startswith(path)).is_empty(): return FolderManager.SUBPATH_EXISTS folder = Folder() folder.root = True folder.name = name folder.path = path store.add(folder) store.commit() return FolderManager.SUCCESS
def __find_folder(self, path, folder): path = os.path.dirname(path) fold = self.__store.find(Folder, Folder.path == path).one() if fold: return fold full_path = folder.path path = path[len(folder.path) + 1:] for name in path.split(os.sep): full_path = os.path.join(full_path, name) fold = self.__store.find(Folder, Folder.path == full_path).one() if not fold: fold = Folder() fold.root = False fold.name = name fold.path = full_path fold.parent = folder self.__store.add(fold) folder = fold return folder
def test_get_music_directory(self): self._make_request('getMusicDirectory', error = 10) self._make_request('getMusicDirectory', { 'id': 'id' }, error = 0) self._make_request('getMusicDirectory', { 'id': str(uuid.uuid4()) }, error = 70) # should test with folders with both children folders and tracks. this code would break in that case with db_session: for f in Folder.select(): rv, child = self._make_request('getMusicDirectory', { 'id': str(f.id) }, tag = 'directory') self.assertEqual(child.get('id'), str(f.id)) self.assertEqual(child.get('name'), f.name) self.assertEqual(len(child), f.children.count() + f.tracks.count()) for dbc, xmlc in zip(sorted(f.children, key = lambda c: c.name), sorted(child, key = lambda c: c.get('title'))): self.assertEqual(dbc.name, xmlc.get('title')) self.assertEqual(xmlc.get('artist'), f.name) self.assertEqual(xmlc.get('parent'), str(f.id)) for t, xmlc in zip(sorted(f.tracks, key = lambda t: t.title), sorted(child, key = lambda c: c.get('title'))): self.assertEqual(t.title, xmlc.get('title')) self.assertEqual(xmlc.get('parent'), str(f.id))
def test_get_indexes(self): self._make_request('getIndexes', { 'musicFolderId': 'abcdef' }, error = 0) self._make_request('getIndexes', { 'musicFolderId': str(uuid.uuid4()) }, error = 70) self._make_request('getIndexes', { 'ifModifiedSince': 'quoi' }, error = 0) rv, child = self._make_request('getIndexes', { 'ifModifiedSince': int(time.time() * 1000 + 1000) }, tag = 'indexes') self.assertEqual(len(child), 0) with db_session: fid = Folder.get(name = 'Empty root').id rv, child = self._make_request('getIndexes', { 'musicFolderId': str(fid) }, tag = 'indexes') self.assertEqual(len(child), 0) rv, child = self._make_request('getIndexes', tag = 'indexes') self.assertEqual(len(child), 3) for i, letter in enumerate([ 'A', 'B', 'C' ]): self.assertEqual(child[i].get('name'), letter) self.assertEqual(len(child[i]), 1) self.assertEqual(child[i][0].get('name'), letter + 'rtist')
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)