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."""
|
"""Initialize an Artist object."""
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.add_children(self.table.sql.albums,
|
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:
|
def add_album(self, album: Album) -> None:
|
||||||
"""Add an Album to this Artist."""
|
"""Add an Album to this Artist."""
|
||||||
if self.table.add_album(self, album):
|
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:
|
def has_album(self, album: Album) -> bool:
|
||||||
"""Check if the Artist has this Album."""
|
"""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:
|
def remove_album(self, album: Album) -> None:
|
||||||
"""Remove an album from this Artist."""
|
"""Remove an album from this Artist."""
|
||||||
self.children.get_filter().remove_row(album)
|
|
||||||
self.table.remove_album(self, album)
|
self.table.remove_album(self, album)
|
||||||
|
self.remove_child(album)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def primary_key(self) -> int:
|
def primary_key(self) -> int:
|
||||||
|
@ -66,7 +67,7 @@ class Filter(table.KeySet):
|
||||||
"""Check if the artist matches the filter."""
|
"""Check if the artist matches the filter."""
|
||||||
res = super().do_match(artist)
|
res = super().do_match(artist)
|
||||||
if not self.show_all and res:
|
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
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ class TestArtistObject(tests.util.TestCase):
|
||||||
def test_init(self):
|
def test_init(self):
|
||||||
"""Test that the Artist is set up properly."""
|
"""Test that the Artist is set up properly."""
|
||||||
self.assertIsInstance(self.artist, emmental.db.playlist.Playlist)
|
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.table, self.table)
|
||||||
self.assertEqual(self.artist.propertyid, 456)
|
self.assertEqual(self.artist.propertyid, 456)
|
||||||
self.assertEqual(self.artist.artistid, 123)
|
self.assertEqual(self.artist.artistid, 123)
|
||||||
|
@ -37,8 +36,7 @@ class TestArtistObject(tests.util.TestCase):
|
||||||
self.artist.add_album(album)
|
self.artist.add_album(album)
|
||||||
|
|
||||||
mock_add.assert_called_with(self.artist, album)
|
mock_add.assert_called_with(self.artist, album)
|
||||||
self.assertSetEqual(self.artist.children.get_filter().keys,
|
self.assertIn(album, self.artist.child_set)
|
||||||
{album.albumid})
|
|
||||||
self.assertTrue(self.artist.has_album(album))
|
self.assertTrue(self.artist.has_album(album))
|
||||||
|
|
||||||
with unittest.mock.patch.object(self.table, "remove_album",
|
with unittest.mock.patch.object(self.table, "remove_album",
|
||||||
|
@ -46,15 +44,18 @@ class TestArtistObject(tests.util.TestCase):
|
||||||
self.artist.remove_album(album)
|
self.artist.remove_album(album)
|
||||||
|
|
||||||
mock_remove.assert_called_with(self.artist, 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))
|
self.assertFalse(self.artist.has_album(album))
|
||||||
|
|
||||||
def test_children(self):
|
def test_children(self):
|
||||||
"""Test that Albums have been added as Artist playlist children."""
|
"""Test that Albums have been added as Artist playlist children."""
|
||||||
self.assertIsInstance(self.artist.children, Gtk.FilterListModel)
|
self.assertIsInstance(self.artist.children, Gtk.FilterListModel)
|
||||||
self.assertIsInstance(self.artist.children.get_filter(),
|
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.children.get_model(), self.sql.albums)
|
||||||
|
self.assertEqual(self.artist.child_set.table, self.sql.albums)
|
||||||
|
|
||||||
|
|
||||||
class TestFilter(tests.util.TestCase):
|
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).name, "Artist 1")
|
||||||
self.assertEqual(artists2.get_item(0).mbid, "")
|
self.assertEqual(artists2.get_item(0).mbid, "")
|
||||||
self.assertSetEqual(artists2.get_item(0).children.get_filter().keys,
|
self.assertSetEqual(artists2.get_item(0).child_set.keyset.keys, {1})
|
||||||
{1})
|
|
||||||
|
|
||||||
self.assertEqual(artists2.get_item(1).name, "Artist 2")
|
self.assertEqual(artists2.get_item(1).name, "Artist 2")
|
||||||
self.assertEqual(artists2.get_item(1).mbid, "ab-cd-ef")
|
self.assertEqual(artists2.get_item(1).mbid, "ab-cd-ef")
|
||||||
self.assertSetEqual(artists2.get_item(1).children.get_filter().keys,
|
self.assertSetEqual(artists2.get_item(1).child_set.keyset.keys, set())
|
||||||
set())
|
|
||||||
|
|
||||||
def test_lookup(self):
|
def test_lookup(self):
|
||||||
"""Test looking up artist playlists."""
|
"""Test looking up artist playlists."""
|
||||||
|
|
Loading…
Reference in New Issue