Exemplo n.º 1
0
    def test_get_files_completion(self):
        """
        Testing whether the right completion of files is returned
        """
        self.mocked_tdef.get_files_with_length = lambda: [("test.txt", 100)]

        handle = MockObject()
        handle.file_progress = lambda **_: [60]
        handle.is_valid = lambda: True
        self.mock_download.handle = handle

        download_state = DownloadState(self.mock_download, MockObject(), None)
        self.assertEqual(download_state.get_files_completion(), [('test.txt', 0.6)])
        handle.file_progress = lambda **_: [0]
        self.assertEqual(download_state.get_files_completion(), [('test.txt', 0.0)])
        handle.file_progress = lambda **_: [100]
        self.assertEqual(download_state.get_files_completion(), [('test.txt', 1.0)])
        self.mocked_tdef.get_files_with_length = lambda: []
        handle.file_progress = lambda **_: []
        self.assertEqual(download_state.get_files_completion(), [])

        # Test a file with a length of zero
        self.mocked_tdef.get_files_with_length = lambda: [("test.txt", 0)]
        handle.file_progress = lambda **_: [0]
        self.assertEqual(download_state.get_files_completion(), [('test.txt', 1.0)])
Exemplo n.º 2
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()
Exemplo n.º 3
0
    def test_remove_unregistered_torrent(self):
        """
        Tests a successful removal status of torrents which aren't known
        """
        self.dlmgr.initialize()
        mock_handle = MockObject()
        mock_handle.is_valid = lambda: False
        alert = type('torrent_removed_alert', (object, ), dict(handle=mock_handle, info_hash='0'*20))
        self.dlmgr.process_alert(alert())

        self.assertNotIn('0' * 20, self.dlmgr.downloads)
Exemplo n.º 4
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()
Exemplo n.º 5
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)