emmental/db/test_playlist.py

95 lines
3.5 KiB
Python

# Copyright 2021 (c) Anna Schumaker.
import db
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 on_refresh(self, plist): self.refreshed = True
def test_init(self):
db.reset()
plist = playlist.Playlist(TestRow(), "missing-icon")
self.assertIsInstance(plist, GObject.GObject)
self.assertFalse(plist.has_children())
self.assertEqual(plist._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)
self.assertIsNone(plist.get_property("plist_state"))
with self.assertRaises(NotImplementedError):
plist.get_property("name")
with self.assertRaises(NotImplementedError):
plist.delete()
def test_passthrough_current(self):
plist = db.user.Table.find("Test Playlist")
self.assertEqual(plist.get_property("current"), -1)
plist.set_property("current", 5)
self.assertEqual(plist.get_property("current"), 5)
self.assertEqual(plist.plist_state.get_property("current"), 5)
def test_passthrough_loop(self):
plist = db.user.Table.find("Test Playlist")
self.assertFalse(plist.get_property("loop"))
plist.set_property("loop", True)
self.assertTrue(plist.get_property("loop"))
self.assertTrue(plist.plist_state.get_property("loop"))
def test_passthrough_random(self):
plist = db.user.Table.find("Test Playlist")
self.assertFalse(plist.get_property("random"))
plist.set_property("random", True)
self.assertTrue(plist.get_property("random"))
self.assertTrue(plist.plist_state.get_property("random"))
def test_passthrough_sort(self):
plist = db.user.Table.find("Test Playlist")
plist.connect("refreshed", self.on_refresh)
self.assertEqual(plist.get_property("sort"), plist.plist_state.sort)
plist.set_property("sort", [ "rowid ASC" ])
self.assertEqual(plist.get_property("sort"), [ "rowid ASC" ])
self.assertEqual(plist.plist_state.get_property("sort"), [ "rowid ASC" ])
self.assertTrue(self.refreshed)
class TestMappedPlaylist(unittest.TestCase):
def test_init(self):
mapped = playlist.MappedPlaylist(TestRow(), "missing-icon", "test_map")
self.assertIsInstance(mapped, playlist.Playlist)
self.assertEqual(mapped._map_table, "test_map")
self.assertEqual(mapped.get_property("map-table"), "test_map")
class TestParentPlaylist(unittest.TestCase):
def test_init(self):
parent = playlist.ParentPlaylist(TestRow(), "missing-icon")
self.assertIsInstance(parent, playlist.Playlist)
self.assertTrue(parent.has_children())
with self.assertRaises(NotImplementedError):
parent.get_child_table()
with self.assertRaises(NotImplementedError):
parent.get_n_children()
with self.assertRaises(NotImplementedError):
parent.get_child(0)
with self.assertRaises(NotImplementedError):
parent.get_child_index(0)