本文整理汇总了Python中Tribler.Test.Core.base_test.MockObject.get_infohash方法的典型用法代码示例。如果您正苦于以下问题:Python MockObject.get_infohash方法的具体用法?Python MockObject.get_infohash怎么用?Python MockObject.get_infohash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Test.Core.base_test.MockObject
的用法示例。
在下文中一共展示了MockObject.get_infohash方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_monitor_downloads_recreate_ip
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_infohash [as 别名]
def test_monitor_downloads_recreate_ip(self):
"""
Test whether an old introduction point is recreated
"""
tribler_session = MockObject()
tribler_session.notifier = MockObject()
tribler_session.notifier.notify = lambda *_: None
tribler_session.lm = MockObject()
tribler_session.lm.ltmgr = MockObject()
tribler_session.lm.ltmgr.get_libtorrent_version = lambda: "1.1.0.0"
self.nodes[0].overlay.tribler_session = tribler_session
mock_state = MockObject()
mock_download = MockObject()
mock_tdef = MockObject()
mock_tdef.get_infohash = lambda: 'a'
mock_download.get_hops = lambda: 1
mock_download.get_def = lambda: mock_tdef
mock_download.add_peer = lambda x: None
mock_download.get_state = lambda: mock_state
mock_state.get_status = lambda: 1
mock_state.get_download = lambda: mock_download
tribler_session.get_downloads = lambda: [mock_download, ]
real_ih = self.nodes[0].overlay.get_lookup_info_hash('a')
self.nodes[0].overlay.infohash_ip_circuits[real_ih] = [(3, 0)]
self.nodes[0].overlay.download_states['a'] = 3
self.nodes[0].overlay.monitor_downloads([mock_state])
self.assertNotEqual(self.nodes[0].overlay.infohash_ip_circuits[real_ih][0][1], 0)
示例2: test_save_resume_preresolved_magnet
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_infohash [as 别名]
def test_save_resume_preresolved_magnet(self):
"""
Test whether a magnet link correctly writes save-resume data before it is resolved.
This can happen when a magnet link is added when the user does not have internet.
"""
self.ltmgr.initialize()
self.ltmgr.trsession = self.tribler_session
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
mock_tdef = MockObject()
mock_tdef.get_infohash = lambda: 'a' * 20
self.tribler_session.get_download = lambda _: None
self.tribler_session.get_downloads_pstate_dir = lambda: self.ltmgr.metadata_tmpdir
mock_lm = MockObject()
mock_lm.ltmgr = self.ltmgr
mock_lm.tunnel_community = None
self.tribler_session.lm = mock_lm
def dl_from_tdef(tdef, _):
dl = LibtorrentDownloadImpl(self.tribler_session, tdef)
dl.setup()
dl.cancel_all_pending_tasks()
return dl
self.tribler_session.start_download_from_tdef = dl_from_tdef
download = self.ltmgr.start_download_from_magnet("magnet:?xt=urn:btih:" + ('1'*40))
basename = hexlify(download.get_def().get_infohash()) + '.state'
filename = os.path.join(download.session.get_downloads_pstate_dir(), basename)
self.assertTrue(os.path.isfile(filename))
示例3: test_start_download_duplicate
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_infohash [as 别名]
def test_start_download_duplicate(self):
"""
Test the starting of a download when there are no new trackers
"""
mock_tdef = MockObject()
mock_tdef.get_infohash = lambda: 'a' * 20
mock_tdef.get_trackers_as_single_tuple = lambda: tuple()
mock_download = MockObject()
mock_download.get_def = lambda: mock_tdef
mock_download.get_credit_mining = lambda: False
self.tribler_session.get_download = lambda _: mock_download
self.tribler_session.start_download_from_tdef = lambda tdef, _: MockObject()
self.ltmgr.tribler_session = self.tribler_session
self.ltmgr.metadata_tmpdir = tempfile.mkdtemp(suffix=u'tribler_metainfo_tmpdir')
self.ltmgr.start_download(infohash='a' * 20, tdef=mock_tdef)
示例4: create_fake_download_and_state
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_infohash [as 别名]
def create_fake_download_and_state():
"""
Create a fake download and state which can be passed to the global download callback.
"""
tdef = TorrentDef()
tdef.get_infohash = lambda: 'aaaa'
fake_peer = {'extended_version': 'Tribler', 'id': 'a' * 20, 'dtotal': 10 * 1024 * 1024}
fake_download = MockObject()
fake_download.get_def = lambda: tdef
fake_download.get_def().get_name_as_unicode = lambda: "test.iso"
fake_download.get_hops = lambda: 0
fake_download.get_safe_seeding = lambda: True
fake_download.get_peerlist = lambda: [fake_peer]
dl_state = MockObject()
dl_state.get_infohash = lambda: 'aaaa'
dl_state.get_status = lambda: DLSTATUS_SEEDING
dl_state.get_download = lambda: fake_download
return fake_download, dl_state
示例5: test_remove_download_by_id_nonempty
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_infohash [as 别名]
def test_remove_download_by_id_nonempty(self):
"""
Remove an existing download.
"""
infohash = "abc"
download = MockObject()
torrent_def = MockObject()
torrent_def.get_infohash = lambda: infohash
download.get_def = lambda: torrent_def
self.session.get_downloads = lambda: [download]
self.called = False
def verify_remove_download_called(*args, **kwargs):
self.called = True
self.session.remove_download = verify_remove_download_called
self.session.remove_download_by_id(infohash)
self.assertTrue(self.called)
示例6: get_def
# 需要导入模块: from Tribler.Test.Core.base_test import MockObject [as 别名]
# 或者: from Tribler.Test.Core.base_test.MockObject import get_infohash [as 别名]
def get_def(self):
a = MockObject()
a.infohash = self.infohash
a.get_name_utf8 = lambda: self.dirname
a.get_infohash = lambda: self.infohash
return a