This is an implementation of an emmental.db.table.Table that adds support for creating Playlists, updating playlist properties, sorting based on playlist name, and displaying playlists with their child playlists in a tree structure. Additionally, I create a playlist_properties table in the database to store properties that all playlists have. Implements: #17 ("Save currently selected playlist") Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
# Copyright 2022 (c) Anna Schumaker
|
|
"""Test our custom db Connection object."""
|
|
import pathlib
|
|
import emmental.db
|
|
import tests.util
|
|
import unittest.mock
|
|
|
|
|
|
class TestConnection(tests.util.TestCase):
|
|
"""Test case for our database connection manager."""
|
|
|
|
def test_paths(self):
|
|
"""Check that path constants are pointing to the right places."""
|
|
script = pathlib.Path(emmental.db.__file__).parent / "emmental.sql"
|
|
self.assertEqual(emmental.db.SQL_SCRIPT, script)
|
|
|
|
def test_connection(self):
|
|
"""Check that the connection manager is initialized properly."""
|
|
self.assertIsInstance(self.sql, emmental.db.connection.Connection)
|
|
|
|
def test_version(self):
|
|
"""Test checking the database schema version."""
|
|
cur = self.sql("PRAGMA user_version")
|
|
self.assertEqual(cur.fetchone()["user_version"], 1)
|
|
|
|
def test_close(self):
|
|
"""Check closing the connection."""
|
|
self.sql.settings.queue.running = True
|
|
|
|
self.sql.close()
|
|
self.assertFalse(self.sql.connected)
|
|
self.assertFalse(self.sql.settings.queue.running)
|
|
|
|
self.sql.close()
|
|
|
|
def test_tables(self):
|
|
"""Check that the connection has pointers to our tables."""
|
|
self.assertIsInstance(self.sql.settings, emmental.db.settings.Table)
|
|
|
|
def test_load(self):
|
|
"""Check that calling load() loads the tables."""
|
|
table_loaded = unittest.mock.Mock()
|
|
self.sql.connect("table-loaded", table_loaded)
|
|
|
|
self.sql.load()
|
|
self.assertTrue(self.sql.settings.loaded)
|
|
|
|
calls = [unittest.mock.call(self.sql, tbl)
|
|
for tbl in [self.sql.settings]]
|
|
table_loaded.assert_has_calls(calls)
|
|
|
|
def test_set_active_playlist(self):
|
|
"""Check setting the active playlist."""
|
|
table = tests.util.playlist.MockTable(self.sql)
|
|
plist1 = table.create(name="Playlist 1")
|
|
plist2 = table.create(name="Playlist 2")
|
|
self.assertIsNone(self.sql.active_playlist)
|
|
|
|
self.sql.set_active_playlist(plist1)
|
|
self.assertEqual(self.sql.active_playlist, plist1)
|
|
self.assertTrue(plist1.active)
|
|
|
|
self.sql.set_active_playlist(plist2)
|
|
self.assertEqual(self.sql.active_playlist, plist2)
|
|
self.assertFalse(plist1.active)
|
|
self.assertTrue(plist2.active)
|
|
|
|
self.sql.set_active_playlist(None)
|
|
self.assertIsNone(self.sql.active_playlist)
|
|
self.assertFalse(plist2.active)
|