def test_monitor_downloads_stop_ip(self): """ Test whether we stop building IPs when a download doesn't exist anymore """ mock_circuit = MockObject() mock_circuit.circuit_id = 0 mock_circuit.ctype = 'IP_SEEDER' mock_circuit.state = 'READY' mock_circuit.info_hash = b'a' mock_circuit.goal_hops = 1 mock_circuit.last_activity = 0 self.nodes[0].overlay.remove_circuit = Mock() self.nodes[0].overlay.circuits[0] = mock_circuit self.nodes[0].overlay.join_swarm(b'a', 1) self.nodes[0].overlay.download_states[b'a'] = 3 self.nodes[0].overlay.monitor_downloads([]) self.nodes[0].overlay.remove_circuit.assert_called_with( 0, 'leaving hidden swarm', destroy=5)
def test_process_error_alert(test_download): """ Testing whether error alerts are processed correctly """ url = "http://google.com" mock_alert = MockObject() mock_alert.msg = None mock_alert.category = lambda: lt.alert.category_t.error_notification mock_alert.status_code = 123 mock_alert.url = url test_download.process_alert(mock_alert, 'tracker_error_alert') assert test_download.tracker_status[url][1] == 'HTTP status code 123' mock_alert.status_code = 0 test_download.process_alert(mock_alert, 'tracker_error_alert') assert test_download.tracker_status[url][1] == 'Timeout'
async def test_remote_select_subscribed_channels(self): """ Test querying remote peers for subscribed channels and updating local votes accordingly """ def mock_notify(overlay, args): overlay.notified_results = True self.assertTrue("results" in args[0]) self.nodes[1].overlay.notifier = MockObject() self.nodes[1].overlay.notifier.notify = lambda sub, args: mock_notify(self.nodes[1].overlay, args) with db_session: # Create one channel with zero contents, to check that only non-empty channels are served self.nodes[0].overlay.mds.ChannelMetadata.create_channel("channel sub", "") for _ in range(0, 5): chan = self.nodes[0].overlay.mds.ChannelMetadata.create_channel("channel sub", "") chan.num_entries = 5 chan.sign() for _ in range(0, 5): channel_uns = self.nodes[0].overlay.mds.ChannelMetadata.create_channel("channel unsub", "") channel_uns.subscribed = False peer = self.nodes[0].my_peer self.nodes[1].overlay.send_remote_select_subscribed_channels(peer) await self.deliver_messages(timeout=0.5) with db_session: received_channels = self.nodes[1].overlay.mds.ChannelMetadata.select(lambda g: g.title == "channel sub") self.assertEqual(received_channels.count(), 5) # Only subscribed channels should have been transported received_channels_all = self.nodes[1].overlay.mds.ChannelMetadata.select() self.assertEqual(received_channels_all.count(), 5) # Make sure the subscribed channels transport counted as voting self.assertEqual( self.nodes[1].overlay.mds.ChannelPeer.select().first().public_key, peer.public_key.key_to_bin()[10:] ) for chan in self.nodes[1].overlay.mds.ChannelMetadata.select(): self.assertTrue(chan.votes > 0.0) # Check that the notifier callback is called on new channel entries self.assertTrue(self.nodes[1].overlay.notified_results)
def test_monitor_downloads_stop_all(self): """ Test whether circuits are removed when all downloads are stopped """ def mocked_remove_circuit(circuit_id, *_, **__): mocked_remove_circuit.circuit_id = circuit_id mocked_remove_circuit.circuit_id = -1 mock_circuit = MockObject() mock_circuit.circuit_id = 0 mock_circuit.ctype = 'DATA' mock_circuit.state = 'READY' mock_circuit.info_hash = b'a' mock_circuit.goal_hops = 1 mock_circuit.last_activity = 0 self.nodes[0].overlay.remove_circuit = mocked_remove_circuit self.nodes[0].overlay.circuits[0] = mock_circuit self.nodes[0].overlay.join_swarm(b'a', 1) self.nodes[0].overlay.download_states[b'a'] = 3 self.nodes[0].overlay.monitor_downloads([]) self.assertEqual(mocked_remove_circuit.circuit_id, 0)
def test_monitor_downloads_intro(self): """ Test whether rendezvous points are removed when a download is stopped """ def mocked_remove_circuit(circuit_id, *_, **__): mocked_remove_circuit.circuit_id = circuit_id mocked_remove_circuit.circuit_id = -1 mock_circuit = MockObject() mock_circuit.circuit_id = 0 mock_circuit.ctype = 'RP_DOWNLOADER' mock_circuit.state = 'READY' mock_circuit.info_hash = b'a' mock_circuit.goal_hops = 1 mock_circuit.last_activity = 0 self.nodes[0].overlay.remove_circuit = mocked_remove_circuit self.nodes[0].overlay.circuits[0] = mock_circuit self.nodes[0].overlay.join_swarm(b'a', 1) self.nodes[0].overlay.swarms[b'a'].add_connection(mock_circuit, None) self.nodes[0].overlay.download_states[b'a'] = 3 self.nodes[0].overlay.monitor_downloads([]) self.assertEqual(mocked_remove_circuit.circuit_id, 0)
async def test_save_resume(self): """ testing call resume data alert """ tdef = self.create_tdef() alert = Mock(resume_data={b'info-hash': tdef.get_infohash()}) dl = Download(self.session, tdef) dl.setup() dl.handle = MockObject() dl.handle.is_valid = lambda: True dl.handle.save_resume_data = lambda: dl.register_task( 'post_alert', dl.process_alert, alert, 'save_resume_data_alert', delay=0.1) await dl.save_resume_data() basename = hexlify(tdef.get_infohash()) + '.conf' filename = self.session.dlmgr.get_checkpoint_dir() / basename dcfg = DownloadConfig.load(filename) self.assertEqual(tdef.get_infohash(), dcfg.get_engineresumedata().get(b'info-hash')) await dl.shutdown()
def test_monitor_downloads_stop_ip(self): """ Test whether we stop building IPs when a download doesn't exist anymore """ def mocked_remove_circuit(circuit_id, *_, **__): mocked_remove_circuit.circuit_id = circuit_id mocked_remove_circuit.circuit_id = -1 mock_circuit = MockObject() mock_circuit.circuit_id = 0 mock_circuit.ctype = 'IP_SEEDER' mock_circuit.state = 'READY' mock_circuit.info_hash = b'a' mock_circuit.goal_hops = 1 self.nodes[0].overlay.remove_circuit = mocked_remove_circuit self.nodes[0].overlay.circuits[0] = mock_circuit self.nodes[0].overlay.join_swarm(b'a', 1) self.nodes[0].overlay.download_states[b'a'] = 3 self.nodes[0].overlay.monitor_downloads([]) self.assertEqual(mocked_remove_circuit.circuit_id, 0)
def test_update_torrent(self): """ Test updating a torrent when a circuit breaks """ self.nodes[0].overlay.find_circuits = lambda: True self.nodes[0].overlay.readd_bittorrent_peers = lambda: None mock_handle = MockObject() mock_handle.get_peer_info = lambda: { Mock(ip=('2.2.2.2', 2)), Mock(ip=('3.3.3.3', 3)) } mock_handle.is_valid = lambda: True mock_download = MockObject() mock_download.handle = mock_handle peers = {('1.1.1.1', 1), ('2.2.2.2', 2)} self.nodes[0].overlay.update_torrent(peers, mock_download) self.assertIn(mock_download, self.nodes[0].overlay.bittorrent_peers) # Test adding peers self.nodes[0].overlay.bittorrent_peers[mock_download] = {('4.4.4.4', 4) } self.nodes[0].overlay.update_torrent(peers, mock_download)
def test_get_valid_next_tracker_for_auto_check(torrent_checker): """ Test if only valid tracker url are used for auto check """ mock_tracker_state_invalid = MockObject() mock_tracker_state_invalid.url = "http://anno nce.torrentsmd.com:8080/announce" mock_tracker_state_valid = MockObject() mock_tracker_state_valid.url = "http://announce.torrentsmd.com:8080/announce" tracker_states = [mock_tracker_state_invalid, mock_tracker_state_valid] def get_next_tracker_for_auto_check(): return tracker_states[0] if tracker_states else None def remove_tracker(_): tracker_states.remove(mock_tracker_state_invalid) torrent_checker.get_next_tracker_for_auto_check = get_next_tracker_for_auto_check torrent_checker.remove_tracker = remove_tracker next_tracker = torrent_checker.get_valid_next_tracker_for_auto_check() assert len(tracker_states) == 1 assert next_tracker.url == "http://announce.torrentsmd.com:8080/announce"
def __init__(self, infohash, dirname): self.infohash = infohash self.dirname = dirname self.tdef = MockObject() self.tdef.get_name_utf8 = lambda: self.dirname self.tdef.get_infohash = lambda: infohash
async def test_check_channels_updates(personal_channel, gigachannel_manager, metadata_store): torrents_added = 0 # We add our personal channel in an inconsistent state to make sure the GigaChannel Manager will # not try to update it in the same way it should update other's channels with db_session: my_channel = metadata_store.ChannelMetadata.get_my_channels().first() my_channel.local_version -= 1 # Subscribed, not updated metadata_store.ChannelMetadata( title="bla1", public_key=b'123', signature=b'345', skip_key_check=True, timestamp=123, local_version=123, subscribed=True, infohash=random_infohash(), ) # Not subscribed, updated metadata_store.ChannelMetadata( title="bla2", public_key=b'124', signature=b'346', skip_key_check=True, timestamp=123, local_version=122, subscribed=False, infohash=random_infohash(), ) # Subscribed, updated - only this one should be downloaded chan3 = metadata_store.ChannelMetadata( title="bla3", public_key=b'125', signature=b'347', skip_key_check=True, timestamp=123, local_version=122, subscribed=True, infohash=random_infohash(), ) def mock_download_channel(chan1): nonlocal torrents_added torrents_added += 1 assert chan1 == chan3 gigachannel_manager.download_channel = mock_download_channel @db_session def fake_get_metainfo(infohash, **_): return { 'info': { 'name': metadata_store.ChannelMetadata.get( infohash=infohash).dirname } } gigachannel_manager.download_manager.get_metainfo = fake_get_metainfo gigachannel_manager.download_manager.metainfo_requests = {} gigachannel_manager.download_manager.download_exists = lambda _: False # Manually fire the channel updates checking routine gigachannel_manager.check_channels_updates() # download_channel should only fire once - for the original subscribed channel assert torrents_added == 1 # Check that downloaded, but unprocessed channel torrent is added to the processing queue gigachannel_manager.download_manager = MockObject() gigachannel_manager.download_manager.download_exists = lambda _: True mock_download = Mock() mock_download.get_state.get_status = DLSTATUS_SEEDING gigachannel_manager.download_manager.get_download = lambda _: mock_download def mock_process_channel_dir(c, _): # Only the subscribed, but not processed (with local_version < timestamp) channel should be processed assert c == chan3 gigachannel_manager.process_channel_dir = mock_process_channel_dir # Manually fire the channel updates checking routine gigachannel_manager.check_channels_updates() await gigachannel_manager.process_queued_channels() # The queue should be empty afterwards assert not gigachannel_manager.channels_processing_queue
async def setUp(self): await super(BaseTestMyChannelEndpoint, self).setUp() self.session.gigachannel_manager = MockObject() self.session.gigachannel_manager.shutdown = lambda: succeed(None) self.session.gigachannel_manager.updated_my_channel = lambda _: succeed(None)
async def test_check_channels_updates(self): # We add our personal channel in an inconsistent state to make sure the GigaChannel Manager will # not try to update it in the same way it should update other's channels with db_session: chan = self.generate_personal_channel() chan.commit_channel_torrent() chan.local_version -= 1 # Subscribed, not updated self.mock_session.mds.ChannelMetadata( title="bla1", public_key=database_blob(b'123'), signature=database_blob(b'345'), skip_key_check=True, timestamp=123, local_version=123, subscribed=True, infohash=random_infohash(), ) # Not subscribed, updated self.mock_session.mds.ChannelMetadata( title="bla2", public_key=database_blob(b'124'), signature=database_blob(b'346'), skip_key_check=True, timestamp=123, local_version=122, subscribed=False, infohash=random_infohash(), ) # Subscribed, updated - only this one should be downloaded chan3 = self.mock_session.mds.ChannelMetadata( title="bla3", public_key=database_blob(b'125'), signature=database_blob(b'347'), skip_key_check=True, timestamp=123, local_version=122, subscribed=True, infohash=random_infohash(), ) self.torrents_added = 0 def mock_download_channel(chan1): self.torrents_added += 1 self.assertEqual(chan1, chan3) self.chanman.download_channel = mock_download_channel @db_session def fake_get_metainfo(infohash, **_): return { 'info': { 'name': self.mock_session.mds.ChannelMetadata.get(infohash=database_blob(infohash)).dirname } } self.mock_session.dlmgr = MockObject() self.mock_session.dlmgr.get_metainfo = fake_get_metainfo self.mock_session.dlmgr.metainfo_requests = {} self.mock_session.dlmgr.download_exists = lambda _: False # Manually fire the channel updates checking routine self.chanman.check_channels_updates() # download_channel should only fire once - for the original subscribed channel self.assertEqual(1, self.torrents_added) # Check that downloaded, but unprocessed channel torrent is added to the processing queue self.mock_session.dlmgr = MockObject() self.mock_session.dlmgr.download_exists = lambda _: True class MockDownload(object): def get_state(self): class MockState(object): def get_status(self): return DLSTATUS_SEEDING return MockState() self.mock_session.dlmgr.get_download = lambda _: MockDownload() def mock_process_channel_dir(c, _): # Only the subscribed, but not processed (with local_version < timestamp) channel should be processed self.assertEqual(c, chan3) self.chanman.process_channel_dir = mock_process_channel_dir # Manually fire the channel updates checking routine self.chanman.check_channels_updates() await self.chanman.process_queued_channels() # The queue should be empty afterwards self.assertEqual(0, len(self.chanman.channels_processing_queue))
def test_getters_setters_2(self): """ Testing various getters and setters in DownloadState """ lt_status = MockObject() lt_status.state = 3 lt_status.upload_rate = 123 lt_status.download_rate = 43 lt_status.total_upload = 100 lt_status.total_download = 200 lt_status.all_time_upload = 100 lt_status.all_time_download = 200 lt_status.list_peers = 10 lt_status.list_seeds = 5 lt_status.progress = 0.75 lt_status.error = False lt_status.paused = False lt_status.state = 3 lt_status.num_pieces = 0 lt_status.pieces = [] lt_status.finished_time = 10 download_state = DownloadState(self.mock_download, lt_status, None) self.assertEqual(download_state.get_status(), DLSTATUS_DOWNLOADING) self.assertEqual(download_state.get_current_speed(UPLOAD), 123) self.assertEqual(download_state.get_current_speed(DOWNLOAD), 43) self.assertEqual(download_state.get_total_transferred(UPLOAD), 100) self.assertEqual(download_state.get_total_transferred(DOWNLOAD), 200) self.assertEqual(download_state.get_seeding_ratio(), 0.5) self.assertEqual(download_state.get_eta(), 0.25) self.assertEqual(download_state.get_num_seeds_peers(), (5, 5)) self.assertEqual(download_state.get_pieces_complete(), []) self.assertEqual(download_state.get_pieces_total_complete(), (0, 0)) self.assertEqual(download_state.get_seeding_time(), 10) lt_status.num_pieces = 6 lt_status.pieces = [1, 1, 1, 0, 0, 0] self.assertEqual(download_state.get_pieces_complete(), [1, 1, 1, 0, 0, 0]) self.assertEqual(download_state.get_pieces_total_complete(), (6, 3)) self.mock_download.config = MockObject() self.mock_download.config.get_selected_files = lambda: ['test'] self.assertEqual(download_state.get_selected_files(), ['test']) self.assertEqual(download_state.get_progress(), 0.75)
async def setUp(self): await TriblerCoreTest.setUp(self) self.download = Download(Mock(), None) mock_handle = MockObject() mock_status = MockObject() mock_status.pieces = [True, False, True, True, False] torrent_info = MockObject() file_info = MockObject() file_info.size = 1234 torrent_info.file_at = lambda _: file_info map_file_result = MockObject() map_file_result.piece = 123 torrent_info.map_file = lambda _dummy1, _dummy2, _dummy3: map_file_result torrent_info.num_pieces = lambda: 5 mock_handle.is_valid = lambda: True mock_handle.status = lambda: mock_status mock_handle.get_torrent_info = lambda: torrent_info mock_handle.set_sequential_download = lambda _: None mock_handle.set_priority = lambda _: None mock_handle.prioritize_pieces = lambda _: None mock_handle.save_resume_data = lambda: None self.download.handle = mock_handle # Create a fake tdef self.download.tdef = MockObject() self.download.tdef.get_name = lambda: "ubuntu.iso" self.download.tdef.get_name_as_unicode = lambda: "ubuntu.iso" self.download.tdef.get_infohash = lambda: b'a' * 20 self.download.tdef.is_multifile_torrent = lambda: False self.download.config = DownloadConfig()
async def test_remove_cruft_channels(self): with db_session: # Our personal chan is created, then updated, so there are 2 files on disk and there are 2 torrents: # the old one and the new one my_chan = self.generate_personal_channel() my_chan.commit_channel_torrent() my_chan_old_infohash = my_chan.infohash _ = self.mock_session.mds.TorrentMetadata.from_dict( dict(self.torrent_template, origin_id=my_chan.id_, status=NEW) ) my_chan.commit_channel_torrent() # Now we add an external channel we are subscribed to. chan2 = self.mock_session.mds.ChannelMetadata( title="bla1", infohash=database_blob(b'123'), public_key=database_blob(b'123'), signature=database_blob(b'345'), skip_key_check=True, timestamp=123, local_version=123, subscribed=True, ) # Another external channel, but there is a catch: we recently unsubscribed from it chan3 = self.mock_session.mds.ChannelMetadata( title="bla2", infohash=database_blob(b'124'), public_key=database_blob(b'124'), signature=database_blob(b'346'), skip_key_check=True, timestamp=123, local_version=123, subscribed=False, ) class MockDownload(MockObject): def __init__(self, infohash, dirname): self.infohash = infohash self.dirname = dirname self.tdef = MockObject() self.tdef.get_name_utf8 = lambda: self.dirname self.tdef.get_infohash = lambda: infohash 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 # Double conversion is required to make sure that buffers signatures are not the same mock_dl_list = [ # Downloads for the personal channel MockDownload(database_blob(bytes(my_chan_old_infohash)), my_chan.dirname), MockDownload(database_blob(bytes(my_chan.infohash)), my_chan.dirname), # Downloads for the updated external channel: "old ones" and "recent" MockDownload(database_blob(b'12331244'), chan2.dirname), MockDownload(database_blob(bytes(chan2.infohash)), chan2.dirname), # Downloads for the unsubscribed external channel MockDownload(database_blob(b'1231551'), chan3.dirname), MockDownload(database_blob(bytes(chan3.infohash)), chan3.dirname), # Orphaned download MockDownload(database_blob(b'333'), u"blabla"), ] def mock_get_channel_downloads(**_): return mock_dl_list self.remove_list = [] def mock_remove(infohash, remove_content=False): d = Future() d.set_result(None) self.remove_list.append((infohash, remove_content)) return d self.mock_session.dlmgr = MockObject() self.mock_session.dlmgr.get_channel_downloads = mock_get_channel_downloads self.chanman.session.dlmgr.remove_download = mock_remove self.chanman.remove_cruft_channels() await self.chanman.process_queued_channels() # We want to remove torrents for (a) deleted channels and (b) unsubscribed channels self.assertCountEqual( self.remove_list, [ (mock_dl_list[0], False), (mock_dl_list[2], False), (mock_dl_list[4], True), (mock_dl_list[5], True), (mock_dl_list[6], True), ], )
async def setUp(self): self.timeout = 15 await super(TestTorrentCheckerSession, self).setUp() self.mock_transport = MockObject() self.mock_transport.write = lambda *_: None self.socket_mgr = FakeUdpSocketManager()
def test_monitor_downloads_recreate_ip(self): """ Test whether an old introduction point is recreated """ mock_state = MockObject() mock_download = MockObject() mock_tdef = MockObject() mock_tdef.get_infohash = lambda: b'a' mock_download.get_def = lambda: mock_tdef mock_download.add_peer = lambda _: succeed(None) mock_download.get_state = lambda: mock_state mock_download.config = MockObject() mock_download.config.get_hops = lambda: 1 mock_download.apply_ip_filter = lambda _: None mock_state.get_status = lambda: 4 mock_state.get_download = lambda: mock_download def mock_create_ip(*_, **__): mock_create_ip.called = True mock_create_ip.called = False self.nodes[0].overlay.create_introduction_point = mock_create_ip self.nodes[0].overlay.download_states[b'a'] = 3 self.nodes[0].overlay.monitor_downloads([mock_state]) self.assertTrue(mock_create_ip.called)
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: b'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_peerlist = lambda: [fake_peer] fake_download.hidden = False fake_download.checkpoint = lambda: succeed(None) fake_download.stop = lambda: succeed(None) fake_download.shutdown = lambda: succeed(None) dl_state = MockObject() dl_state.get_infohash = lambda: b'aaaa' dl_state.get_status = lambda: DLSTATUS_SEEDING dl_state.get_download = lambda: fake_download fake_config = MockObject() fake_config.get_hops = lambda: 0 fake_config.get_safe_seeding = lambda: True fake_download.config = fake_config return fake_download, dl_state
def test_on_tunnel_in(self): """ Test whether no data is sent to the SOCKS5 server when we receive data from the tunnels """ mock_circuit = MockObject() mock_circuit.goal_hops = 300 mock_circuit.circuit_id = b'a' mock_circuit.ctype = CIRCUIT_TYPE_DATA origin = ("0.0.0.0", 1024) self.assertFalse( self.dispatcher.on_incoming_from_tunnel(self.mock_tunnel_community, mock_circuit, origin, b'a')) mock_circuit.goal_hops = 1 mock_sock_server = MockObject() mock_session = MockObject() mock_session._udp_socket = None mock_sock_server.sessions = [mock_session] self.dispatcher.set_socks_servers([mock_sock_server]) self.dispatcher.destinations[1] = {b'a': mock_circuit} self.assertFalse( self.dispatcher.on_incoming_from_tunnel(self.mock_tunnel_community, mock_circuit, origin, b'a')) mock_session._udp_socket = MockObject() mock_session._udp_socket.sendDatagram = lambda _: True self.assertTrue( self.dispatcher.on_incoming_from_tunnel(self.mock_tunnel_community, mock_circuit, origin, b'a'))
def __init__(self, _): super(ChannelsEndpoint, self).__init__(MockObject())
async def test_multifile_torrent(self): # Achtung! This test is completely and utterly broken, as is the whole libtorrent wrapper! # Don't try to understand it, it is a legacy thing! tdef = TorrentDef() tdef.add_content(TESTS_DATA_DIR / "video.avi") tdef.set_tracker("http://tribler.org/announce") tdef.save() fake_handler = MockObject() fake_handler.is_valid = lambda: True fake_handler.status = lambda: fake_status fake_handler.set_share_mode = lambda _: None fake_handler.set_priority = lambda _: None fake_handler.set_sequential_download = lambda _: None fake_handler.resume = lambda: None fake_handler.set_max_connections = lambda _: None fake_handler.apply_ip_filter = lambda _: None fake_handler.save_resume_data = lambda: None fake_status = MockObject() fake_status.share_mode = False dl = Download(self.session, tdef) dl.set_selected_files = lambda: None dl.future_added = succeed(fake_handler) # Create a dummy download config dl.config = DownloadConfig() dl.config.set_engineresumedata({ b"save_path": path_util.abspath(self.state_dir), b"info-hash": b'\x00' * 20 }) dl.setup() dl.config.set_engineresumedata({ b"save_path": path_util.abspath(self.state_dir), b"info-hash": b'\x00' * 20 }) dl.setup() dl.config.set_engineresumedata({ b"save_path": "some_local_dir", b"info-hash": b'\x00' * 20 }) dl.setup() await dl.shutdown()
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
def mock_download_from_tdef(*_, **__): global initiated_download initiated_download = True mock_dl = MockObject() mock_dl.future_finished = succeed(None) return mock_dl
def create_mock_status(self): status = MockObject() status.state = 3 status.upload_rate = 123 status.download_rate = 43 status.upload_payload_rate = 123 status.download_payload_rate = 43 status.total_upload = 100 status.total_download = 200 status.all_time_upload = 100 status.all_time_download = 200 status.list_peers = 10 status.list_seeds = 5 status.progress = 0.75 status.error = False status.paused = False status.state = 3 status.num_pieces = 0 status.pieces = [] return status