db: Have Artist playlists use the new child_set
I switch over to adding and removing Albums using the generic add_child() and remove_child() functions. I also switch from using a KeySet filter holding albumids to a Gtk.CustomFilter that calls Artist.has_album() to check if an Album is in the set. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
5ee86a9b5e
commit
4f15bde850
|
@ -19,21 +19,22 @@ class Artist(playlist.Playlist):
|
|||
"""Initialize an Artist object."""
|
||||
super().__init__(**kwargs)
|
||||
self.add_children(self.table.sql.albums,
|
||||
table.KeySet(self.table.get_albumids(self)))
|
||||
Gtk.CustomFilter.new(self.has_album),
|
||||
self.table.get_albumids(self))
|
||||
|
||||
def add_album(self, album: Album) -> None:
|
||||
"""Add an Album to this Artist."""
|
||||
if self.table.add_album(self, album):
|
||||
self.children.get_filter().add_row(album)
|
||||
self.add_child(album)
|
||||
|
||||
def has_album(self, album: Album) -> bool:
|
||||
"""Check if the Artist has this Album."""
|
||||
return self.children.get_filter().match(album)
|
||||
return self.has_child(album)
|
||||
|
||||
def remove_album(self, album: Album) -> None:
|
||||
"""Remove an album from this Artist."""
|
||||
self.children.get_filter().remove_row(album)
|
||||
self.table.remove_album(self, album)
|
||||
self.remove_child(album)
|
||||
|
||||
@property
|
||||
def primary_key(self) -> int:
|
||||
|
@ -66,7 +67,7 @@ class Filter(table.KeySet):
|
|||
"""Check if the artist matches the filter."""
|
||||
res = super().do_match(artist)
|
||||
if not self.show_all and res:
|
||||
return artist.children.get_filter().n_keys > 0
|
||||
return artist.child_set.keyset.n_keys > 0
|
||||
return res
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ class TestArtistObject(tests.util.TestCase):
|
|||
def test_init(self):
|
||||
"""Test that the Artist is set up properly."""
|
||||
self.assertIsInstance(self.artist, emmental.db.playlist.Playlist)
|
||||
self.assertSetEqual(self.artist.children.get_filter().keys, set())
|
||||
self.assertEqual(self.artist.table, self.table)
|
||||
self.assertEqual(self.artist.propertyid, 456)
|
||||
self.assertEqual(self.artist.artistid, 123)
|
||||
|
@ -37,8 +36,7 @@ class TestArtistObject(tests.util.TestCase):
|
|||
self.artist.add_album(album)
|
||||
|
||||
mock_add.assert_called_with(self.artist, album)
|
||||
self.assertSetEqual(self.artist.children.get_filter().keys,
|
||||
{album.albumid})
|
||||
self.assertIn(album, self.artist.child_set)
|
||||
self.assertTrue(self.artist.has_album(album))
|
||||
|
||||
with unittest.mock.patch.object(self.table, "remove_album",
|
||||
|
@ -46,15 +44,18 @@ class TestArtistObject(tests.util.TestCase):
|
|||
self.artist.remove_album(album)
|
||||
|
||||
mock_remove.assert_called_with(self.artist, album)
|
||||
self.assertSetEqual(self.artist.children.get_filter().keys, set())
|
||||
self.assertNotIn(album, self.artist.child_set)
|
||||
self.assertFalse(self.artist.has_album(album))
|
||||
|
||||
def test_children(self):
|
||||
"""Test that Albums have been added as Artist playlist children."""
|
||||
self.assertIsInstance(self.artist.children, Gtk.FilterListModel)
|
||||
self.assertIsInstance(self.artist.children.get_filter(),
|
||||
emmental.db.table.KeySet)
|
||||
Gtk.CustomFilter)
|
||||
self.assertIsInstance(self.artist.child_set,
|
||||
emmental.db.table.TableSubset)
|
||||
self.assertEqual(self.artist.children.get_model(), self.sql.albums)
|
||||
self.assertEqual(self.artist.child_set.table, self.sql.albums)
|
||||
|
||||
|
||||
class TestFilter(tests.util.TestCase):
|
||||
|
@ -219,13 +220,11 @@ class TestArtistTable(tests.util.TestCase):
|
|||
|
||||
self.assertEqual(artists2.get_item(0).name, "Artist 1")
|
||||
self.assertEqual(artists2.get_item(0).mbid, "")
|
||||
self.assertSetEqual(artists2.get_item(0).children.get_filter().keys,
|
||||
{1})
|
||||
self.assertSetEqual(artists2.get_item(0).child_set.keyset.keys, {1})
|
||||
|
||||
self.assertEqual(artists2.get_item(1).name, "Artist 2")
|
||||
self.assertEqual(artists2.get_item(1).mbid, "ab-cd-ef")
|
||||
self.assertSetEqual(artists2.get_item(1).children.get_filter().keys,
|
||||
set())
|
||||
self.assertSetEqual(artists2.get_item(1).child_set.keyset.keys, set())
|
||||
|
||||
def test_lookup(self):
|
||||
"""Test looking up artist playlists."""
|
||||
|
|
Loading…
Reference in New Issue