emmental/db/test_album.py

61 lines
2.2 KiB
Python

# Copyright 2021 (c) Anna Schumaker.
import db
import sqlite3
import unittest
from gi.repository import GObject
class TestAlbum(unittest.TestCase):
def setUp(self):
db.reset()
def test_init(self):
artist = db.artist.Table.find("Test Artist", "Test Sort")
album = artist.find_album("Test Album")
self.assertIsInstance(album, db.playlist.ParentPlaylist)
self.assertEqual(album.get_property("name"), "Test Album")
self.assertEqual(album.get_property("icon-name"), "media-optical-cd-audio")
self.assertEqual(album.get_child_table(), db.disc.Table)
def test_delete(self):
artist = db.artist.Table.find("Test Artist", "Test Sort")
album = artist.find_album("Test Album")
album.delete()
self.assertIsNone(db.album.Table.lookup(artist, "Test Album"))
def test_find_disc(self):
artist = db.artist.Table.find("Test Artist", "Test Sort")
album = artist.find_album("Test Album")
disc = album.find_disc(1, None)
self.assertIsInstance(disc, db.disc.Disc)
class TestAlbumTable(unittest.TestCase):
def setUp(self):
db.reset()
def test_init(self):
table = db.album.AlbumTable()
self.assertIsInstance(table, db.playlist.ChildModel)
self.assertEqual(table.table, "albums")
self.assertEqual(table.parent, "artistid")
self.assertEqual(table.order, "sort")
self.assertIsInstance(db.album.Table, db.album.AlbumTable)
db.sql.execute("SELECT albumid,artistid,plstateid,name,sort FROM albums")
def test_insert(self):
artist = db.artist.Table.insert("Test Artist", "Test Sort")
album = artist.find_album("Test Album")
self.assertIsInstance(album, db.album.Album)
self.assertEqual(album._name, "Test Album")
with self.assertRaises(sqlite3.IntegrityError):
db.album.Table.insert(artist, "Test Album")
def test_lookup(self):
artist = db.artist.Table.insert("Test Artist", "Test Sort")
album = artist.find_album("Test Album")
self.assertEqual(db.album.Table.lookup(artist, "Test Album"), album)
self.assertIsNone(db.album.Table.lookup(artist, "none"))