當前位置: 首頁>>代碼示例>>Python>>正文


Python TorrentDBHandler.addOrGetTorrentIDSReturn方法代碼示例

本文整理匯總了Python中Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler.addOrGetTorrentIDSReturn方法的典型用法代碼示例。如果您正苦於以下問題:Python TorrentDBHandler.addOrGetTorrentIDSReturn方法的具體用法?Python TorrentDBHandler.addOrGetTorrentIDSReturn怎麽用?Python TorrentDBHandler.addOrGetTorrentIDSReturn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler的用法示例。


在下文中一共展示了TorrentDBHandler.addOrGetTorrentIDSReturn方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestTorrentDBHandler

# 需要導入模塊: from Tribler.Core.CacheDB.SqliteCacheDBHandler import TorrentDBHandler [as 別名]
# 或者: from Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler import addOrGetTorrentIDSReturn [as 別名]

#.........這裏部分代碼省略.........
    def test_add_external_torrent_no_def_no_files(self):
        infohash = unhexlify('48865489ac16e2f34ea0cd3043cfd970cc24ec09')
        self.tdb.addExternalTorrentNoDef(infohash, "test torrent", [], [], 1234)
        self.assertFalse(self.tdb.hasTorrent(infohash))

    def test_add_external_torrent_no_def_one_file(self):
        infohash = unhexlify('49865489ac16e2f34ea0cd3043cfd970cc24ec09')
        self.tdb.addExternalTorrentNoDef(infohash, "test torrent", [("file1", 42)],
                                         ['http://localhost/announce'], 1234)
        self.assertTrue(self.tdb.getTorrentID(infohash))

    def test_add_external_torrent_no_def_more_files(self):
        infohash = unhexlify('50865489ac16e2f34ea0cd3043cfd970cc24ec09')
        self.tdb.addExternalTorrentNoDef(infohash, "test torrent", [("file1", 42), ("file2", 43)],
                                         [], 1234, extra_info={"seeder": 2, "leecher": 3})
        self.assertTrue(self.tdb.getTorrentID(infohash))

    def test_add_external_torrent_no_def_invalid(self):
        infohash = unhexlify('50865489ac16e2f34ea0cd3043cfd970cc24ec09')
        self.tdb.addExternalTorrentNoDef(infohash, "test torrent", [("file1", {}), ("file2", 43)],
                                         [], 1234)
        self.assertFalse(self.tdb.getTorrentID(infohash))

    def test_add_get_torrent_id(self):
        infohash = str2bin('AA8cTG7ZuPsyblbRE7CyxsrKUCg=')
        self.assertEqual(self.tdb.addOrGetTorrentID(infohash), 1)

        new_infohash = unhexlify('50865489ac16e2f34ea0cd3043cfd970cc24ec09')
        self.assertEqual(self.tdb.addOrGetTorrentID(new_infohash), 4859)

    def test_add_get_torrent_ids_return(self):
        infohash = str2bin('AA8cTG7ZuPsyblbRE7CyxsrKUCg=')
        new_infohash = unhexlify('50865489ac16e2f34ea0cd3043cfd970cc24ec09')
        tids, inserted = self.tdb.addOrGetTorrentIDSReturn([infohash, new_infohash])
        self.assertEqual(tids, [1, 4859])
        self.assertEqual(len(inserted), 1)

    def test_index_torrent_existing(self):
        self.tdb._indexTorrent(1, "test", [])

    def test_getCollectedTorrentHashes(self):
        res = self.tdb.getNumberCollectedTorrents()
        self.assertEqual(res, 4847)

    def test_freeSpace(self):
        # Manually set the torrent store because register is not called.
        self.session.lm.torrent_store = LevelDbStore(self.session.config.get_torrent_store_dir())
        old_res = self.tdb.getNumberCollectedTorrents()
        self.tdb.freeSpace(20)
        res = self.tdb.getNumberCollectedTorrents()
        self.session.lm.torrent_store.close()
        self.assertEqual(res, old_res-20)

    def test_get_search_suggestions(self):
        self.assertEqual(self.tdb.getSearchSuggestion(["content", "cont"]), ["content 1"])

    def test_get_autocomplete_terms(self):
        self.assertEqual(len(self.tdb.getAutoCompleteTerms("content", 100)), 0)

    def test_get_recently_randomly_collected_torrents(self):
        self.assertEqual(len(self.tdb.getRecentlyCollectedTorrents(limit=10)), 10)
        self.assertEqual(len(self.tdb.getRandomlyCollectedTorrents(100000000, limit=10)), 3)

    def test_get_recently_checked_torrents(self):
        self.assertEqual(len(self.tdb.getRecentlyCheckedTorrents(limit=5)), 5)
開發者ID:synctext,項目名稱:tribler,代碼行數:69,代碼來源:test_sqlitecachedbhandler_torrents.py


注:本文中的Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler.addOrGetTorrentIDSReturn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。