db: Give Playlists a "rowkey" property

Most playlists will use this to look up their tracks in the track table

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2021-10-14 13:34:33 -04:00
parent 371878a53a
commit a52a815338
10 changed files with 26 additions and 4 deletions

View File

@ -7,7 +7,8 @@ from . import table
class Playlist(GObject.GObject):
def __init__(self, row, icon_name):
GObject.GObject.__init__(self)
self._rowid = row[0]
self._rowkey = row.keys()[0]
self._rowid = row[self._rowkey]
self._plstate = state.Table.get(row["plstateid"])
self._icon_name = icon_name
@ -27,6 +28,9 @@ class Playlist(GObject.GObject):
@GObject.Property
def rowid(self): return self._rowid
@GObject.Property
def rowkey(self): return self._rowkey
class ParentPlaylist(Playlist):
def has_children(self): return True

View File

@ -49,6 +49,7 @@ class TestAlbumTable(unittest.TestCase):
self.assertIsInstance(album, db.album.Album)
self.assertEqual(album._name, "Test Album")
self.assertEqual(album._rowkey, "albumid")
with self.assertRaises(sqlite3.IntegrityError):
db.album.Table.insert(artist, "Test Album")

View File

@ -45,6 +45,7 @@ class TestArtistTable(unittest.TestCase):
self.assertIsInstance(artist, db.artist.Artist)
self.assertEqual(artist._name, "Test Artist")
self.assertEqual(artist._rowkey, "artistid")
with self.assertRaises(sqlite3.IntegrityError):
db.artist.Table.insert("Test Artist", "Test Sort")

View File

@ -56,6 +56,7 @@ class TestDecadeTable(unittest.TestCase):
self.assertIsInstance(decade, db.decade.Decade)
self.assertEqual(decade._decade, 2020)
self.assertEqual(decade._rowkey, "decadeid")
with self.assertRaises(sqlite3.IntegrityError):
db.decade.Table.insert(2020)

View File

@ -66,6 +66,7 @@ class TestDiscTable(unittest.TestCase):
self.assertIsInstance(disc, db.disc.Disc)
self.assertEqual(disc._number, 1)
self.assertEqual(disc._subtitle, "subtitle")
self.assertEqual(disc._rowkey, "discid")
with self.assertRaises(sqlite3.IntegrityError):
db.disc.Table.insert(album, 1, "subtitle")

View File

@ -41,6 +41,7 @@ class TestGenreTable(unittest.TestCase):
self.assertIsInstance(genre, db.genre.Genre)
self.assertEqual(genre._name, "Test Genre")
self.assertEqual(genre._rowkey, "genreid")
with self.assertRaises(sqlite3.IntegrityError):
db.genre.Table.insert("Test Genre")

View File

@ -55,6 +55,7 @@ class TestLibraryTable(unittest.TestCase):
self.assertIsInstance(library, db.library.Library)
self.assertIsInstance(library._plstate, db.state.PlaylistState)
self.assertEqual(library._rowkey, "libraryid")
self.assertEqual(library._path, pathlib.Path("/a/b/c"))
self.assertTrue(library._enabled)

View File

@ -4,17 +4,27 @@ import unittest
from gi.repository import GObject
from . import playlist
class TestRow:
def __init__(self): pass
def keys(self): return [ "testid", "plstateid" ]
def __getitem__(self, key):
if key == "testid" or key == 0: return 1
return 10
class TestPlaylist(unittest.TestCase):
def test_init(self):
db.reset()
plist = playlist.Playlist({ 0:1, "plstateid":10 }, "missing-icon")
plist = playlist.Playlist(TestRow(), "missing-icon")
self.assertIsInstance(plist, GObject.GObject)
self.assertFalse(plist.has_children())
self.assertEqual(plist._rowid, 1)
self.assertEqual(plist.get_property("rowid"), 1)
self.assertEqual(plist._rowkey, "testid")
self.assertEqual(plist._icon_name, "missing-icon")
self.assertEqual(plist.get_property("rowid"), 1)
self.assertEqual(plist.get_property("rowkey"), "testid")
self.assertEqual(plist.get_property("icon-name"), "missing-icon")
self.assertIsNone(plist._plstate)
@ -28,7 +38,7 @@ class TestPlaylist(unittest.TestCase):
class TestParentPlaylist(unittest.TestCase):
def test_init(self):
parent = playlist.ParentPlaylist({ 0:1, "plstateid":10 }, "missing-icon")
parent = playlist.ParentPlaylist(TestRow(), "missing-icon")
self.assertIsInstance(parent, playlist.Playlist)
self.assertTrue(parent.has_children())

View File

@ -72,6 +72,7 @@ class TestUserTable(unittest.TestCase):
self.assertIsInstance(playlist, db.user.UserPlaylist)
self.assertEqual(playlist._name, "Test Playlist")
self.assertEqual(playlist._rowkey, "playlistid")
with self.assertRaises(sqlite3.IntegrityError):
db.user.Table.insert("Test Playlist")

View File

@ -42,6 +42,7 @@ class TestYearTable(unittest.TestCase):
self.assertIsInstance(year, db.year.Year)
self.assertEqual(year._year, 2021)
self.assertEqual(year._rowkey, "yearid")
with self.assertRaises(sqlite3.IntegrityError):
db.year.Table.insert(decade, 2021)