Skip to content

Commit

Permalink
Make name field binary in torrentdef references and in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xoriole committed Jan 22, 2024
1 parent 94dfae1 commit 8f1e383
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ async def start_download_from_uri(self, uri, config=None):
tdef = TorrentDef.load_from_dict(self.metainfo_cache[infohash]['meta_info'])
else:
self._logger.info('Metainfo not found in cache')
tdef = TorrentDefNoMetainfo(infohash, "Unknown name" if not name else name, url=uri)
tdef = TorrentDefNoMetainfo(infohash, b"Unknown name" if not name else name, url=uri)
return await self.start_download(tdef=tdef, config=config)
if scheme == FILE_SCHEME:
self._logger.info('File scheme detected')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async def test_start_download_while_getting_metainfo(fake_dlmgr):
fake_dlmgr.remove_download = AsyncMock(return_value=succeed(None))

tdef = TorrentDefNoMetainfo(
infohash, "name", f"magnet:?xt=urn:btih:{hexlify(infohash)}&"
infohash, b"name", f"magnet:?xt=urn:btih:{hexlify(infohash)}&"
)
download = await fake_dlmgr.start_download(tdef=tdef, checkpoint_disabled=True)
assert metainfo_dl != download
Expand Down Expand Up @@ -222,7 +222,7 @@ async def test_start_download(fake_dlmgr):
fake_dlmgr.get_session = MagicMock(return_value=mock_ltsession)

download = await fake_dlmgr.start_download(
tdef=TorrentDefNoMetainfo(infohash, ""), checkpoint_disabled=True
tdef=TorrentDefNoMetainfo(infohash, b""), checkpoint_disabled=True
)
handle = await download.get_handle()
assert handle == mock_handle
Expand Down Expand Up @@ -273,7 +273,7 @@ async def test_start_download_existing_handle(fake_dlmgr):
fake_dlmgr.get_session = MagicMock(return_value=mock_ltsession)

download = await fake_dlmgr.start_download(
tdef=TorrentDefNoMetainfo(infohash, "name"), checkpoint_disabled=True
tdef=TorrentDefNoMetainfo(infohash, b"name"), checkpoint_disabled=True
)
handle = await download.get_handle()
assert handle == mock_handle
Expand Down Expand Up @@ -508,7 +508,7 @@ async def test_start_download_from_magnet_no_name(fake_dlmgr: DownloadManager):
# Test whether a download is started with `Unknown name` name when the magnet has no name
magnet = f'magnet:?xt=urn:btih:{"A" * 40}'
download = await fake_dlmgr.start_download_from_uri(magnet)
assert download.tdef.get_name() == 'Unknown name'
assert download.tdef.get_name() == b'Unknown name'


def test_update_trackers(fake_dlmgr) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/tribler/core/components/libtorrent/torrentdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,5 +554,5 @@ def torrent_info(self) -> lt.torrent_info | None:
def load_torrent_info(self) -> None:
pass

def get_name_as_unicode(self):
def get_name_as_unicode(self) -> str:
return self.get_name_utf8()

0 comments on commit 8f1e383

Please sign in to comment.