def test_find_container(self): container = Container() show1 = Show("path", "showname") show2 = Show("path", "showname2") container.containers.append(show1) show1.containers.append(show2) self.assertTrue( testutils.compare_containers(show1, container.find_container(show1.id()))) self.assertTrue( testutils.compare_containers(container.find_container(show2.id()), show2)) self.assertIsNone(container.find_container("foobar"))
def test_init(self): extra = Extra("path", "showname", 1) self.assertIsInstance(extra, Container) self.assertIsInstance(extra, MediaLibrary) self.assertIsInstance(extra, Show) self.assertIsInstance(extra, Season) self.assertIsInstance(extra, Extra) extra = Extra("path", "showname", 1) self.assertIsNone(extra.parent()) parent = Container() extra = Extra("path", "showname", 1, parent=parent) self.assertTrue(testutils.compare_containers(extra.parent(), parent)) PATH = "path" extra = Extra(PATH, "showname", 1) season = Season(PATH, "showname", 1) self.assertEqual(PATH, season.path()) SHOW_NAME = "showname" extra = Extra("path", SHOW_NAME, 1) self.assertEqual(extra.show_name(), SHOW_NAME) SEASON_NUMBER = 22 extra = Extra("path", "showname", SEASON_NUMBER) self.assertEqual(extra.season_number(), SEASON_NUMBER)
def test_parent(self): container = Container() self.assertIsNone(container.parent()) parent = Container() container = Container(parent=parent) self.assertTrue( testutils.compare_containers(container.parent(), parent)) container.set_parent(None) self.assertIsNone(container.parent())
def test_init(self): mediaLibrary = MediaLibrary("path") self.assertIsInstance(mediaLibrary, Container) self.assertIsInstance(mediaLibrary, MediaLibrary) self.assertNotIsInstance(mediaLibrary, Show) self.assertNotIsInstance(mediaLibrary, Season) self.assertNotIsInstance(mediaLibrary, Extra) mediaLibrary = MediaLibrary("path") self.assertIsNone(mediaLibrary.parent()) parent = Container() mediaLibrary = MediaLibrary("path", parent=parent) self.assertTrue( testutils.compare_containers(mediaLibrary.parent(), parent))
def test_init(self): show = Show("path", "showname") self.assertIsInstance(show, Container) self.assertIsInstance(show, MediaLibrary) self.assertIsInstance(show, Show) self.assertNotIsInstance(show, Season) self.assertNotIsInstance(show, Extra) show = Show("path", "showname") self.assertIsNone(show.parent()) parent = Container() show = Show("path", "showname", parent=parent) self.assertTrue(testutils.compare_containers(show.parent(), parent)) PATH = "path" show = Show(PATH, "showname") self.assertEqual(PATH, show.path())
def test_watchlist(self): root, containers, media = create_test_library() db = Sqlite() db.connect(database=TMP_DB) db.create_containers_table() db.create_media_table() db.update_media(media) db.update_containers(containers) db.create_watchlist_table() container = containers[0] CONTAINER_ID = container.id() self.assertFalse(db.is_in_watchlists(CONTAINER_ID)) db.add_to_watchlist([CONTAINER_ID]) self.assertTrue(db.is_in_watchlists(CONTAINER_ID)) list = db.get_watchlist() self.assertEqual(len(list), 1) self.assertTrue(testutils.compare_containers(list[0], container)) db.remove_from_watchlist([CONTAINER_ID]) self.assertFalse(db.is_in_watchlists(CONTAINER_ID)) db.add_to_watchlist([containers[0].id(), containers[1].id()]) self.assertEqual(len(db.get_watchlist()), 2) db.remove_all_from_watchlist() self.assertEqual(len(db.get_watchlist()), 0) db.add_to_watchlist([CONTAINER_ID]) self.assertTrue(db.is_in_watchlists(CONTAINER_ID)) db.delete_containers([container]) self.assertIsNone(db.get_container(CONTAINER_ID)) list = db.get_watchlist() self.assertEqual(len(list), 0) self.assertFalse(db.is_in_watchlists(CONTAINER_ID)) db.close()
def test_init(self): container = Container() self.assertIsInstance(container, Container) self.assertNotIsInstance(container, MediaLibrary) self.assertNotIsInstance(container, Show) self.assertNotIsInstance(container, Season) self.assertNotIsInstance(container, Extra) container = Container() self.assertIsNone(container.parent()) parent = Container() container = Container(parent=parent) self.assertTrue( testutils.compare_containers(container.parent(), parent)) container = Show("path", "showname") self.assertIsInstance(container, Container) self.assertIsInstance(container, MediaLibrary) self.assertIsInstance(container, Show) self.assertNotIsInstance(container, Season) self.assertNotIsInstance(container, Extra) container = Season("path", "showname", 1) self.assertIsInstance(container, Container) self.assertIsInstance(container, MediaLibrary) self.assertIsInstance(container, Show) self.assertIsInstance(container, Season) self.assertNotIsInstance(container, Extra) container = Extra("path", "showname", 1) self.assertIsInstance(container, Container) self.assertIsInstance(container, MediaLibrary) self.assertIsInstance(container, Show) self.assertIsInstance(container, Season) self.assertIsInstance(container, Extra)
def test_init(self): season = Season("path", "showname", 1) self.assertIsInstance(season, Container) self.assertIsInstance(season, MediaLibrary) self.assertIsInstance(season, Show) self.assertIsInstance(season, Season) self.assertNotIsInstance(season, Extra) season = Season("path", "showname", 1) self.assertIsNone(season.parent()) parent = Container() season = Season("path", "showname", 1, parent=parent) self.assertTrue(testutils.compare_containers(season.parent(), parent)) PATH = "path" season = Season(PATH, "showname", 1) self.assertEqual(PATH, season.path()) SHOW_NAME = "showname" season = Season("path", SHOW_NAME, 1) self.assertEqual(season.show_name(), SHOW_NAME)
def test_update_and_get_containers(self): root, containers, media = create_test_library() db = Sqlite() db.connect(database=TMP_DB) db.create_containers_table() db.create_media_table() db.update_media(media) db.update_meta(create_test_meta()) db.update_containers(containers) sql = f'select count() from containers' cur = db.conn.cursor() cur.execute(sql) count = cur.fetchone()[0] self.assertEqual(count, len(containers)) for con in containers: db_container = db.get_container(con.id()) self.assertTrue(testutils.compare_containers(con, db_container)) # dublicates con = containers[0] db.update_containers([con]) sql = f'select count() from containers where id=?' cur = db.conn.cursor() cur.execute(sql, (con.id(), )) count = cur.fetchone()[0] self.assertEqual(count, 1) a_season = None for con in containers: if isinstance(con, Season): a_season = con break if a_season: a_season._path = a_season.path() + "foo" a_season._show_name = a_season.show_name() + "foo" a_season._season_number = a_season.season_number() + 1 a_season._parent = None if (len(a_season.containers)): a_season.containers.clear() else: for c in containers: if isinstance(c, Extra): a_season.containers.append(c) c.set_parent(a_season) break if (len(a_season.media)): a_season.media.clear() else: for m in media: if isinstance(m, Episode): a_season.media.append(m) m.set_parent(a_season) break db.update_containers([a_season]) db_container = db.get_container(a_season.id()) self.assertTrue( testutils.compare_containers(a_season, db_container)) db.close()