本文整理汇总了Python中Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler.addExternalTorrentNoDef方法的典型用法代码示例。如果您正苦于以下问题:Python TorrentDBHandler.addExternalTorrentNoDef方法的具体用法?Python TorrentDBHandler.addExternalTorrentNoDef怎么用?Python TorrentDBHandler.addExternalTorrentNoDef使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler
的用法示例。
在下文中一共展示了TorrentDBHandler.addExternalTorrentNoDef方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTorrentDBHandler
# 需要导入模块: from Tribler.Core.CacheDB.SqliteCacheDBHandler import TorrentDBHandler [as 别名]
# 或者: from Tribler.Core.CacheDB.SqliteCacheDBHandler.TorrentDBHandler import addExternalTorrentNoDef [as 别名]
#.........这里部分代码省略.........
self.assertFalse(self.tdb.getInfohash(1234567))
def test_add_update_torrent(self):
self.addTorrent()
self.updateTorrent()
def test_update_torrent_from_metainfo(self):
# Add torrent first
infohash = unhexlify('ed81da94d21ad1b305133f2726cdaec5a57fed98')
# Only infohash is added to the database
self.tdb.addOrGetTorrentID(infohash)
# Then update the torrent with metainfo
metainfo = {'info': {'files': [{'path': ['Something.something.pdf'], 'length': 123456789},
{'path': ['Another-thing.jpg'], 'length': 100000000}],
'piece length': 2097152,
'name': '\xc3Something awesome (2015)',
'pieces': ''},
'seeders': 0, 'initial peers': [],
'leechers': 36, 'download_exists': False, 'nodes': []}
self.tdb.update_torrent_with_metainfo(infohash, metainfo)
# Check updates are correct
torrent_id = self.tdb.getTorrentID(infohash)
name = self.tdb.getOne('name', torrent_id=torrent_id)
self.assertEqual(name, u'\xc3Something awesome (2015)')
num_files = self.tdb.getOne('num_files', torrent_id=torrent_id)
self.assertEqual(num_files, 2)
length = self.tdb.getOne('length', torrent_id=torrent_id)
self.assertEqual(length, 223456789)
def test_add_external_torrent_no_def_existing(self):
infohash = str2bin('AA8cTG7ZuPsyblbRE7CyxsrKUCg=')
self.tdb.addExternalTorrentNoDef(infohash, "test torrent", [], [], 1234)
self.assertTrue(self.tdb.hasTorrent(infohash))
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)