Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
    def test__update_identifiables(self):
        root, containers, media = create_test_library()
        identifiables = [
            i for i in (containers + media) if isinstance(i, Identifiable)
        ]

        db = Sqlite()
        db.connect(database=TMP_DB)

        db.create_containers_table()
        db.update_containers(containers)
        db.create_media_table()
        db.update_media(media)
        db.update_meta(create_test_meta())

        sql = f'select count() from identifiables'
        cur = db.conn.cursor()
        cur.execute(sql)
        count = cur.fetchone()[0]

        self.assertEqual(count, len(identifiables))

        for ide in identifiables:
            if isinstance(ide, Container):
                db_identifiable = db.get_container(ide.id())
            else:
                db_identifiable = db.get_media(ide.id())

            self.assertTrue(
                testutils.compare_identifiables(ide, db_identifiable))

        # dublicates
        ide = identifiables[0]
        db._update_identifiables([ide])

        sql = f'select count() from identifiables where id=?'
        cur = db.conn.cursor()
        cur.execute(sql, (ide.id(), ))
        count = cur.fetchone()[0]

        self.assertEqual(count, 1)

        an_identifiable = identifiables[0]

        if an_identifiable:
            year = an_identifiable.year() + 1 if an_identifiable.year() else 1
            an_identifiable.set_year(year)
            an_identifiable.ext_ids()["foo"] = "bar"

            if isinstance(an_identifiable, Container):
                db.update_containers([an_identifiable])
                db_identifiable = db.get_container(an_identifiable.id())
            else:
                db.update_media([an_identifiable])
                db_identifiable = db.get_media(an_identifiable.id())

            self.assertTrue(
                testutils.compare_identifiables(an_identifiable,
                                                db_identifiable))

        db.close()
Exemplo n.º 3
0
    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()