Skip to content

Commit

Permalink
Flake&Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jan 21, 2022
1 parent d412faf commit 1b054fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/tribler-common/tribler_common/rest_constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MAGNET_PREFIX = 'magnet'
HTTP_PREFIX = 'http'
FILE_PREFIX = 'file'
FILE_PREFIX = 'file'
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1b054fa

Please sign in to comment.