diff --git a/src/tribler-common/tribler_common/rest_constants.py b/src/tribler-common/tribler_common/rest_constants.py index 7363685b245..0944191557d 100644 --- a/src/tribler-common/tribler_common/rest_constants.py +++ b/src/tribler-common/tribler_common/rest_constants.py @@ -1,3 +1,3 @@ MAGNET_PREFIX = 'magnet' HTTP_PREFIX = 'http' -FILE_PREFIX = 'file' \ No newline at end of file +FILE_PREFIX = 'file' diff --git a/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py index 9c253a8275b..8c131cf2921 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/tests/test_torrentinfo_endpoint.py @@ -25,6 +25,9 @@ SAMPLE_CHANNEL_FILES_DIR = TESTS_DIR / "data" / "sample_channel" +# pylint: disable=redefined-outer-name + + @pytest.fixture def download_manager(state_dir): dlmgr = Mock() @@ -61,7 +64,8 @@ async def test_get_torrentinfo_escaped_characters(tmp_path, rest_api): destination = tmp_path / 'ubuntu%20%21 15.04.torrent' shutil.copyfile(source, destination) - response = await do_request(rest_api, url='torrentinfo', params={'uri': f'{FILE_PREFIX}:{destination}'}, expected_code=200) + response = await do_request(rest_api, url='torrentinfo', params={'uri': f'{FILE_PREFIX}:{destination}'}, + expected_code=200) assert 'metainfo' in response diff --git a/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py b/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py index 6ffaf9be448..9165c198780 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py +++ b/src/tribler-core/tribler_core/components/libtorrent/restapi/torrentinfo_endpoint.py @@ -3,12 +3,16 @@ from copy import deepcopy from aiohttp import ClientResponseError, ClientSession, ServerConnectionError, web + from aiohttp_apispec import docs -from marshmallow.fields import String from ipv8.REST.schema import schema + +from marshmallow.fields import String + from tribler_common.rest_constants import FILE_PREFIX, HTTP_PREFIX, MAGNET_PREFIX from tribler_common.simpledefs import NTFY + from tribler_core.components.libtorrent.download_manager.download_manager import DownloadManager from tribler_core.components.libtorrent.torrentdef import TorrentDef from tribler_core.components.libtorrent.utils.libtorrent_helper import libtorrent as lt diff --git a/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py index 9665a26c4ac..b058bc85295 100644 --- a/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py +++ b/src/tribler-core/tribler_core/components/libtorrent/tests/test_download_api.py @@ -2,33 +2,32 @@ import pytest -from tribler_common.rest_constants import HTTP_PREFIX +from tribler_common.rest_constants import FILE_PREFIX from tribler_common.simpledefs import DLSTATUS_DOWNLOADING from tribler_core.tests.tools.common import TORRENT_UBUNTU_FILE -async def download_from_file(file_name, tmp_path, file_server, download_manager): - shutil.copyfile(TORRENT_UBUNTU_FILE, tmp_path / "ubuntu.torrent") - download = await download_manager.start_download_from_uri(f'{HTTP_PREFIX}://localhost:{file_server}/ubuntu.torrent') - await download.wait_for_status(DLSTATUS_DOWNLOADING) - - @pytest.mark.asyncio @pytest.mark.timeout(10) async def test_download_torrent_from_url(tmp_path, file_server, download_manager): - await download_from_file('ubuntu.torrent', tmp_path, file_server, download_manager) + # Setup file server to serve torrent file + shutil.copyfile(TORRENT_UBUNTU_FILE, tmp_path / "ubuntu.torrent") + download = await download_manager.start_download_from_uri(f'http://localhost:{file_server}/ubuntu.torrent') + await download.wait_for_status(DLSTATUS_DOWNLOADING) @pytest.mark.asyncio @pytest.mark.timeout(10) -async def test_download_torrent_from_url_escaped_characters(tmp_path, file_server, download_manager): - # test for the bug fix: https://github.com/Tribler/tribler/issues/6700 - await download_from_file('ubuntu%20%21 15.04.torrent', tmp_path, file_server, download_manager) +async def test_download_torrent_from_file(download_manager): + d = await download_manager.start_download_from_uri(TORRENT_UBUNTU_FILE.as_uri()) + await d.wait_for_status(DLSTATUS_DOWNLOADING) @pytest.mark.asyncio @pytest.mark.timeout(10) -async def test_download_torrent_from_file(download_manager): - d = await download_manager.start_download_from_uri(TORRENT_UBUNTU_FILE.as_uri()) +async def test_download_torrent_from_file_with_escaped_characters(download_manager, tmp_path): + destination = tmp_path / 'ubuntu%20%21 15.04.torrent' + shutil.copyfile(TORRENT_UBUNTU_FILE, destination) + d = await download_manager.start_download_from_uri(f'{FILE_PREFIX}:{destination}') await d.wait_for_status(DLSTATUS_DOWNLOADING)