2019-04-19 14:45:39 -04:00
|
|
|
# Copyright 2019 (c) Anna Schumaker
|
|
|
|
from . import artist
|
|
|
|
from . import node
|
2019-06-01 22:34:06 -04:00
|
|
|
from . import playlist
|
2019-04-19 14:45:39 -04:00
|
|
|
from .. import notify
|
2019-12-09 10:05:00 -05:00
|
|
|
from .. import trak
|
2019-04-19 14:45:39 -04:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
test_album = os.path.join("./trier/Test Library/Test Artist 01/Test Album 1")
|
2019-04-19 14:45:39 -04:00
|
|
|
|
|
|
|
class TestArtistPlaylist(unittest.TestCase):
|
2019-06-01 22:34:06 -04:00
|
|
|
def setUp(self):
|
2019-12-04 10:39:41 -05:00
|
|
|
notify.clear()
|
2019-12-09 14:05:41 -05:00
|
|
|
trak.reset()
|
2019-04-19 14:45:39 -04:00
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
def test_artist_node(self):
|
2019-04-19 14:45:39 -04:00
|
|
|
anode = artist.ArtistNode()
|
|
|
|
self.assertIsInstance(anode, node.PlaylistNode)
|
|
|
|
self.assertEqual(anode.name, "Artists")
|
2019-04-19 17:00:39 -04:00
|
|
|
self.assertEqual(anode.icon, "avatar-default-symbolic")
|
2019-04-19 14:45:39 -04:00
|
|
|
|
2019-08-16 10:00:09 -04:00
|
|
|
def test_artist_alloc_child(self):
|
2019-06-01 22:34:06 -04:00
|
|
|
anode = artist.ArtistNode()
|
2019-08-16 10:00:09 -04:00
|
|
|
plist = anode.alloc_child("Test Artist", artist.ARTIST_ICON)
|
2019-06-01 22:34:06 -04:00
|
|
|
self.assertIsInstance(plist, artist.ArtistPlaylist)
|
|
|
|
self.assertEqual(plist.name, "Test Artist")
|
|
|
|
self.assertEqual(plist.icon, "avatar-default-symbolic")
|
|
|
|
self.assertEqual(plist.sort_order, [ "album", "discnumber", "tracknumber" ])
|
2019-04-19 14:45:39 -04:00
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
def test_artist_node_new_track(self):
|
|
|
|
anode = artist.ArtistNode()
|
|
|
|
self.assertEqual(anode.n_children(), 0)
|
|
|
|
|
2019-12-09 14:05:41 -05:00
|
|
|
track = trak.lookup(os.path.join(test_album, "01 - Test Track 01.ogg"))
|
2019-06-01 22:34:06 -04:00
|
|
|
self.assertEqual(anode.n_children(), 1)
|
2019-04-19 14:45:39 -04:00
|
|
|
plist = anode.nth_child(0)
|
|
|
|
self.assertEqual(plist.name, "Test Artist 01")
|
2019-04-19 17:00:39 -04:00
|
|
|
self.assertEqual(plist.icon, "avatar-default-symbolic")
|
2019-06-01 22:34:06 -04:00
|
|
|
self.assertEqual(plist[0], track)
|
2019-04-24 09:30:12 -04:00
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
def test_artist_node_reset(self):
|
|
|
|
anode = artist.ArtistNode()
|
|
|
|
anode.children.append(42)
|
|
|
|
notify.cancel("new-track", anode.new_track)
|
2019-04-19 14:45:39 -04:00
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
anode.reset()
|
|
|
|
self.assertEqual(len(anode.children), 0)
|
2019-12-04 10:39:41 -05:00
|
|
|
self.assertIn((anode.new_track, False), notify.events["new-track"])
|
2019-04-19 14:45:39 -04:00
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
def test_artist_playlist_alloc(self):
|
2019-08-16 10:00:09 -04:00
|
|
|
anode = artist.ArtistPlaylist("Test Playlist", artist.ARTIST_ICON)
|
|
|
|
album = anode.alloc_child("Test Album", artist.ALBUM_ICON)
|
2019-04-19 14:45:39 -04:00
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
self.assertIsInstance(album, playlist.Playlist)
|
|
|
|
self.assertEqual(album.name, "Test Album")
|
|
|
|
self.assertEqual(album.icon, "media-optical-cd-audio")
|
|
|
|
self.assertEqual(album.sort_order, [ "discnumber", "tracknumber" ])
|
2019-04-19 14:45:39 -04:00
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
def test_artist_playlist_add(self):
|
|
|
|
anode = artist.ArtistNode()
|
2019-12-09 14:05:41 -05:00
|
|
|
track = trak.lookup(os.path.join(test_album, "01 - Test Track 01.ogg"))
|
2019-06-01 22:34:06 -04:00
|
|
|
plist = anode.nth_child(0)
|
2019-04-19 14:45:39 -04:00
|
|
|
|
2019-06-01 22:34:06 -04:00
|
|
|
self.assertEqual(plist.n_children(), 1)
|
|
|
|
album = plist.nth_child(0)
|
|
|
|
self.assertIsInstance(album, playlist.Playlist)
|
|
|
|
self.assertEqual(album.name, "Test Album 1")
|