Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Jul 3, 2023
1 parent c1f6442 commit a98e596
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
9 changes: 0 additions & 9 deletions src/tribler/core/components/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest.mock import MagicMock

import pytest
from aiohttp.abc import Application
from ipv8.keyvault.private.libnaclkey import LibNaCLSK
from ipv8.util import succeed

Expand All @@ -11,7 +10,6 @@
from tribler.core.components.libtorrent.settings import LibtorrentSettings
from tribler.core.components.libtorrent.torrentdef import TorrentDef
from tribler.core.components.metadata_store.db.store import MetadataStore
from tribler.core.components.restapi.rest.rest_manager import error_middleware
from tribler.core.config.tribler_config import TriblerConfig
from tribler.core.tests.tools.common import TESTS_DATA_DIR
from tribler.core.utilities.path_util import Path
Expand Down Expand Up @@ -132,10 +130,3 @@ async def download_manager(tmp_path_factory):
yield download_manager

await download_manager.shutdown()


@pytest.fixture(name='web_app')
async def web_app_fixture():
app = Application(middlewares=[error_middleware])
yield app
await app.shutdown()
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ def knowledge_endpoint(knowledge_db):
endpoint = KnowledgeEndpoint(knowledge_db, community)
return endpoint


@pytest.fixture
def rest_api(web_app, event_loop, aiohttp_client, knowledge_endpoint):
web_app.add_subapp('/knowledge', knowledge_endpoint.app)
yield event_loop.run_until_complete(aiohttp_client(web_app))
async def rest_api(event_loop, aiohttp_client, knowledge_endpoint):
app = Application()
app.add_subapp('/knowledge', knowledge_endpoint.app)

yield await aiohttp_client(app)

await app.shutdown()


def tag_to_statement(tag: str) -> Dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
@pytest.fixture
async def rest_api(event_loop, aiohttp_client, mock_dlmgr, metadata_store): # pylint: disable=unused-argument
endpoint = DownloadsEndpoint(mock_dlmgr, metadata_store=metadata_store)
web_app.add_subapp('/downloads', endpoint.app)
yield event_loop.run_until_complete(aiohttp_client(web_app))

app = Application(middlewares=[error_middleware])
app.add_subapp('/downloads', endpoint.app)

yield await aiohttp_client(app)

await endpoint.shutdown()
await app.shutdown()


def get_hex_infohash(tdef):
return hexlify(tdef.get_infohash())

Expand Down Expand Up @@ -149,12 +149,12 @@ def test_get_extended_status_circuits(mock_extended_status):


@unittest.mock.patch("tribler.core.components.libtorrent.restapi.downloads_endpoint.ensure_unicode",
Mock(side_effect=UnicodeDecodeError("", b"", 0, 0, "")))
Mock(side_effect=UnicodeDecodeError("", b"", 0, 0, "")))
def test_safe_extended_peer_info():
"""
Test that we return the string mapped by `chr` in the case of `UnicodeDecodeError`
"""
extended_peer_info = download_endpoint._safe_extended_peer_info(b"abcd") # pylint: disable=protected-access
extended_peer_info = download_endpoint._safe_extended_peer_info(b"abcd") # pylint: disable=protected-access
assert extended_peer_info == "abcd"


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch
from unittest.mock import MagicMock, patch

import pytest
from aiohttp.web_app import Application
Expand Down Expand Up @@ -32,15 +32,12 @@ async def core_resource_monitor(tmp_path):


@pytest.fixture
async def rest_api(event_loop, aiohttp_client, mock_tunnel_community, tmp_path,
core_resource_monitor):
async def rest_api(event_loop, aiohttp_client, mock_tunnel_community, tmp_path, core_resource_monitor):
endpoint = DebugEndpoint(tmp_path, tmp_path / 'logs',
tunnel_community=mock_tunnel_community,
resource_monitor=core_resource_monitor)

endpoint.tunnel_community = mock_tunnel_community
web_app.add_subapp('/debug', endpoint.app)
yield event_loop.run_until_complete(aiohttp_client(web_app))

app = Application(middlewares=[error_middleware])
app.add_subapp('/debug', endpoint.app)
Expand Down

0 comments on commit a98e596

Please sign in to comment.