예제 #1
0
    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()
예제 #2
0
    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()