db: Give Artists a function for listing their Albums
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
6a1713630b
commit
94f08dcd06
|
@ -9,6 +9,7 @@
|
|||
# +------------------+
|
||||
# | name -> artistid |
|
||||
# +------------------+
|
||||
from . import album
|
||||
from . import execute
|
||||
from . import objects
|
||||
|
||||
|
@ -17,6 +18,11 @@ class Artist(objects.Tag):
|
|||
return execute(f"SELECT {column} FROM artists "
|
||||
"WHERE artistid=?", [ self.rowid ])
|
||||
|
||||
def albums(self):
|
||||
cursor = execute(f"SELECT albumid FROM albums "
|
||||
"WHERE artistid=?", [ self.rowid ])
|
||||
return [ album.Album(row["albumid"]) for row in cursor.fetchall() ]
|
||||
|
||||
|
||||
class ArtistTable(objects.Table):
|
||||
def __init__(self):
|
||||
|
|
|
@ -49,3 +49,9 @@ class TestArtistTable(unittest.TestCase):
|
|||
artist = db.artist.Table.insert("Test Artist", "Test Sort")
|
||||
self.assertEqual(db.artist.Table.lookup("Test Artist"), artist)
|
||||
self.assertIsNone(db.artist.Table.lookup("none"))
|
||||
|
||||
def test_artist_albums(self):
|
||||
artist = db.artist.Table.find("Test Artist", "Test Sort")
|
||||
a = db.album.Table.find(artist, "A")
|
||||
b = db.album.Table.find(artist, "B")
|
||||
self.assertEqual(artist.albums(), [ a, b ])
|
||||
|
|
Loading…
Reference in New Issue