Пример #1
0
    def test_artist(self):
        artist = db.Artist()
        artist.name = u'Test Artist'
        self.store.add(artist)

        # Assuming SQLite doesn't enforce foreign key constraints
        MockUser = namedtuple(u'User', [ u'id' ])
        user = MockUser(uuid.uuid4())

        star = db.StarredArtist()
        star.user_id = user.id
        star.starred_id = artist.id
        self.store.add(star)

        artist_dict = artist.as_subsonic_artist(user)
        self.assertIsInstance(artist_dict, dict)
        self.assertIn(u'id', artist_dict)
        self.assertIn(u'name', artist_dict)
        self.assertIn(u'albumCount', artist_dict)
        self.assertIn(u'starred', artist_dict)
        self.assertEqual(artist_dict[u'name'], u'Test Artist')
        self.assertEqual(artist_dict[u'albumCount'], 0)
        self.assertRegexpMatches(artist_dict[u'starred'], date_regex)

        album = db.Album()
        album.name = u'Test Artist' # self-titled
        artist.albums.add(album)

        album = db.Album()
        album.name = u'The Album After The Frist One'
        artist.albums.add(album)

        artist_dict = artist.as_subsonic_artist(user)
        self.assertEqual(artist_dict[u'albumCount'], 2)
Пример #2
0
    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,
        )
Пример #3
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)
Пример #4
0
    def test_album(self):
        artist = db.Artist(name="Test Artist")
        album = db.Album(artist=artist, name="Test Album")

        user = self.create_user()
        db.StarredAlbum(user=user, starred=album)

        # No tracks, shouldn't be stored under normal circumstances
        self.assertRaises(ValueError, album.as_subsonic_album, user)

        root_folder, folder_art, folder_noart = self.create_some_folders()
        track1 = self.create_track_in(folder_noart,
                                      root_folder,
                                      artist=artist,
                                      album=album)

        album_dict = album.as_subsonic_album(user)
        self.assertIsInstance(album_dict, dict)
        self.assertIn("id", album_dict)
        self.assertIn("name", album_dict)
        self.assertIn("artist", album_dict)
        self.assertIn("artistId", album_dict)
        self.assertIn("songCount", album_dict)
        self.assertIn("duration", album_dict)
        self.assertIn("created", album_dict)
        self.assertIn("starred", album_dict)
        self.assertIn("coverArt", album_dict)
        self.assertEqual(album_dict["name"], album.name)
        self.assertEqual(album_dict["artist"], artist.name)
        self.assertEqual(album_dict["artistId"], str(artist.id))
        self.assertEqual(album_dict["songCount"], 1)
        self.assertEqual(album_dict["duration"], 5)
        self.assertEqual(album_dict["coverArt"], str(track1.id))
        self.assertRegex(album_dict["created"], date_regex)
        self.assertRegex(album_dict["starred"], date_regex)
Пример #5
0
    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")
Пример #6
0
    def test_artist(self):
        artist = db.Artist(name="Test Artist")

        user = self.create_user()
        db.StarredArtist(user=user, starred=artist)

        artist_dict = artist.as_subsonic_artist(user)
        self.assertIsInstance(artist_dict, dict)
        self.assertIn("id", artist_dict)
        self.assertIn("name", artist_dict)
        self.assertIn("albumCount", artist_dict)
        self.assertIn("starred", artist_dict)
        self.assertEqual(artist_dict["name"], "Test Artist")
        self.assertEqual(artist_dict["albumCount"], 0)
        self.assertRegex(artist_dict["starred"], date_regex)

        db.Album(name="Test Artist", artist=artist)  # self-titled
        db.Album(name="The Album After The First One", artist=artist)

        artist_dict = artist.as_subsonic_artist(user)
        self.assertEqual(artist_dict["albumCount"], 2)
Пример #7
0
    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()
Пример #8
0
    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()
Пример #9
0
    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
Пример #10
0
    def test_album(self):
        artist = db.Artist()
        artist.name = u'Test Artist'

        album = db.Album()
        album.artist = artist
        album.name = u'Test Album'

        # Assuming SQLite doesn't enforce foreign key constraints
        MockUser = namedtuple(u'User', [ u'id' ])
        user = MockUser(uuid.uuid4())

        star = db.StarredAlbum()
        star.user_id = user.id
        star.starred = album

        self.store.add(album)
        self.store.add(star)

        # No tracks, shouldn't be stored under normal circumstances
        self.assertRaises(ValueError, album.as_subsonic_album, user)

        self.create_some_tracks(artist, album)

        album_dict = album.as_subsonic_album(user)
        self.assertIsInstance(album_dict, dict)
        self.assertIn(u'id', album_dict)
        self.assertIn(u'name', album_dict)
        self.assertIn(u'artist', album_dict)
        self.assertIn(u'artistId', album_dict)
        self.assertIn(u'songCount', album_dict)
        self.assertIn(u'duration', album_dict)
        self.assertIn(u'created', album_dict)
        self.assertIn(u'starred', album_dict)
        self.assertEqual(album_dict[u'name'], album.name)
        self.assertEqual(album_dict[u'artist'], artist.name)
        self.assertEqual(album_dict[u'artistId'], str(artist.id))
        self.assertEqual(album_dict[u'songCount'], 2)
        self.assertEqual(album_dict[u'duration'], 8)
        self.assertRegexpMatches(album_dict[u'created'], date_regex)
        self.assertRegexpMatches(album_dict[u'starred'], date_regex)
Пример #11
0
 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,
     )
Пример #12
0
    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