def create_folders(self): # Add test folders self.assertIsNotNone(FolderManager.add("media", self.media_dir)) self.assertIsNotNone(FolderManager.add("music", self.music_dir)) db.Folder(root=False, name="non-root", path=os.path.join(self.music_dir, "subfolder")) artist = db.Artist(name="Artist") album = db.Album(name="Album", artist=artist) root = db.Folder.get(name="media") db.Track( title="Track", artist=artist, album=album, disc=1, number=1, path=os.path.join(self.media_dir, "somefile"), folder=root, root_folder=root, duration=2, bitrate=320, last_modification=0, )
def create_data(self): # Create some users self.assertIsInstance( UserManager.add("alice", "ALICE", "*****@*****.**", True), db.User) self.assertIsInstance( UserManager.add("bob", "BOB", "*****@*****.**", False), db.User) self.assertIsInstance( UserManager.add("charlie", "CHARLIE", "*****@*****.**", False), db.User) folder = db.Folder(name="Root", path="tests/assets", root=True) artist = db.Artist(name="Artist") album = db.Album(name="Album", artist=artist) track = db.Track( title="Track", disc=1, number=1, duration=1, artist=artist, album=album, path="tests/assets/empty", folder=folder, root_folder=folder, bitrate=320, last_modification=0, ) playlist = db.Playlist(name="Playlist", user=db.User.get(name="alice")) playlist.add(track)
def setUp(self): db.init_database("sqlite:") with db_session: root = db.Folder(root=True, name="Folder", path="tests") artist = db.Artist(name="Artist") album = db.Album(artist=artist, name="Album") for i in range(3): db.Track( title="Track {}".format(i), album=album, artist=artist, disc=1, number=i + 1, duration=3, has_art=False, bitrate=64, path="tests/track{}".format(i), last_modification=2, root_folder=root, folder=root, genre="Genre", ) db.User(name="user", password="******", salt="sugar")
def create_some_tracks(self, artist = None, album = None): root, child = self.create_some_folders() if not artist: artist = db.Artist() artist.name = u'Test Artist' if not album: album = db.Album() album.artist = artist album.name = u'Test Album' track1 = db.Track() track1.title = u'Track Title' track1.album = album track1.artist = artist track1.disc = 1 track1.number = 1 track1.duration = 3 track1.bitrate = 320 track1.path = u'tests/assets/empty' track1.content_type = u'audio/mpeg' track1.last_modification = 1234 track1.root_folder = root track1.folder = child self.store.add(track1) track2 = db.Track() track2.title = u'One Awesome Song' track2.album = album track2.artist = artist track2.disc = 1 track2.number = 2 track2.duration = 5 track2.bitrate = 96 track2.path = u'tests/assets/empty' track2.content_type = u'audio/mpeg' track2.last_modification = 1234 track2.root_folder = root track2.folder = child self.store.add(track2) return track1, track2
def create_some_tracks(self, artist=None, album=None): root, child, child_2 = self.create_some_folders() if not artist: artist = db.Artist(name="Test artist") if not album: album = db.Album(artist=artist, name="Test Album") track1 = db.Track( title="Track Title", album=album, artist=artist, disc=1, number=1, duration=3, has_art=True, bitrate=320, path="tests/assets/formats/silence.ogg", last_modification=1234, root_folder=root, folder=child, ) track2 = db.Track( title="One Awesome Song", album=album, artist=artist, disc=1, number=2, duration=5, bitrate=96, path="tests/assets/23bytes", last_modification=1234, root_folder=root, folder=child, ) return track1, track2
def setUp(self): # Create an empty sqlite database in memory self.store = db.get_store("sqlite:") # Read schema from file with io.open('schema/sqlite.sql', 'r') as sql: schema = sql.read() # Create tables on memory database for command in schema.split(';'): self.store.execute(command) # Create some temporary directories self.media_dir = tempfile.mkdtemp() self.music_dir = tempfile.mkdtemp() # Add test folders self.assertEqual( FolderManager.add(self.store, 'media', self.media_dir), FolderManager.SUCCESS) self.assertEqual( FolderManager.add(self.store, 'music', self.music_dir), FolderManager.SUCCESS) folder = db.Folder() folder.root = False folder.name = 'non-root' folder.path = os.path.join(self.music_dir, 'subfolder') self.store.add(folder) artist = db.Artist() artist.name = 'Artist' album = db.Album() album.name = 'Album' album.artist = artist root = self.store.find(db.Folder, db.Folder.name == 'media').one() track = db.Track() track.title = 'Track' track.artist = artist track.album = album track.disc = 1 track.number = 1 track.path = os.path.join(self.media_dir, 'somefile') track.folder = root track.root_folder = root track.duration = 2 track.content_type = 'audio/mpeg' track.bitrate = 320 track.last_modification = 0 self.store.add(track) self.store.commit()
def setUp(self): # Create an empty sqlite database in memory self.store = db.get_store("sqlite:") # Read schema from file with io.open('schema/sqlite.sql', 'r') as sql: schema = sql.read() # Create tables on memory database for command in schema.split(';'): self.store.execute(command) # Create some users self.assertEqual(UserManager.add(self.store, 'alice', 'ALICE', '*****@*****.**', True), UserManager.SUCCESS) self.assertEqual(UserManager.add(self.store, 'bob', 'BOB', '*****@*****.**', False), UserManager.SUCCESS) self.assertEqual(UserManager.add(self.store, 'charlie', 'CHARLIE', '*****@*****.**', False), UserManager.SUCCESS) folder = db.Folder() folder.name = 'Root' folder.path = 'tests/assets' folder.root = True artist = db.Artist() artist.name = 'Artist' album = db.Album() album.name = 'Album' album.artist = artist track = db.Track() track.title = 'Track' track.disc = 1 track.number = 1 track.duration = 1 track.artist = artist track.album = album track.path = 'tests/assets/empty' track.folder = folder track.root_folder = folder track.duration = 2 track.content_type = 'audio/mpeg' track.bitrate = 320 track.last_modification = 0 self.store.add(track) self.store.commit() playlist = db.Playlist() playlist.name = 'Playlist' playlist.user = self.store.find(db.User, db.User.name == 'alice').one() playlist.add(track) self.store.add(playlist) self.store.commit()
def create_track_in(self, folder, root, artist=None, album=None, has_art=True): artist = artist or db.Artist(name="Snazzy Artist") album = album or db.Album(artist=artist, name="Rockin' Album") return db.Track( title="Nifty Number", album=album, artist=artist, disc=1, number=1, duration=5, has_art=has_art, bitrate=96, path="tests/assets/formats/silence.flac", last_modification=1234, root_folder=root, folder=folder, )