From 1fc17bef8980ac41d2fa7c48d4634b1321f0cc9d Mon Sep 17 00:00:00 2001 From: Helder Sepulveda Date: Wed, 8 May 2024 12:50:55 -0400 Subject: [PATCH] Update the unit tests --- .../components/restapi/rest/tests/test_events_endpoint.py | 5 +++-- .../core/components/restapi/rest/tests/test_rest_manager.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tribler/core/components/restapi/rest/tests/test_events_endpoint.py b/src/tribler/core/components/restapi/rest/tests/test_events_endpoint.py index 3a19f6516c7..f5b27f3daec 100644 --- a/src/tribler/core/components/restapi/rest/tests/test_events_endpoint.py +++ b/src/tribler/core/components/restapi/rest/tests/test_events_endpoint.py @@ -51,9 +51,10 @@ async def fixture_rest_manager(api_port, tmp_path, events_endpoint): config = TriblerConfig() config.api.http_enabled = True config.api.http_port = api_port + config.set_state_dir(tmp_path) root_endpoint = RootEndpoint(middlewares=[ApiKeyMiddleware(config.api.key), error_middleware]) root_endpoint.add_endpoint('/events', events_endpoint) - rest_manager = RESTManager(config=config.api, root_endpoint=root_endpoint, state_dir=tmp_path) + rest_manager = RESTManager(config=config, root_endpoint=root_endpoint) await rest_manager.start() yield rest_manager @@ -62,7 +63,7 @@ async def fixture_rest_manager(api_port, tmp_path, events_endpoint): async def open_events_socket(rest_manager_, connected_event, events_up): global messages_to_wait_for - port = rest_manager_.config.http_port + port = rest_manager_.config.api.http_port url = f'http://localhost:{port}/events' headers = {'User-Agent': 'Tribler ' + version_id} diff --git a/src/tribler/core/components/restapi/rest/tests/test_rest_manager.py b/src/tribler/core/components/restapi/rest/tests/test_rest_manager.py index 7328c8bca06..a920d596ee5 100644 --- a/src/tribler/core/components/restapi/rest/tests/test_rest_manager.py +++ b/src/tribler/core/components/restapi/rest/tests/test_rest_manager.py @@ -34,6 +34,7 @@ def api_port_fixture(free_port): @pytest.fixture(name='rest_manager') async def rest_manager_fixture(request, tribler_config, api_port, tmp_path): config = tribler_config + config.set_state_dir(tmp_path) api_key_marker = request.node.get_closest_marker("api_key") if api_key_marker is not None: tribler_config.api.key = api_key_marker.args[0] @@ -49,7 +50,7 @@ async def rest_manager_fixture(request, tribler_config, api_port, tmp_path): tribler_config.api.http_port = api_port root_endpoint = RootEndpoint(middlewares=[ApiKeyMiddleware(config.api.key), error_middleware]) root_endpoint.add_endpoint('/settings', SettingsEndpoint(config)) - rest_manager = RESTManager(config=config.api, root_endpoint=root_endpoint, state_dir=tmp_path) + rest_manager = RESTManager(config=config, root_endpoint=root_endpoint) await rest_manager.start() yield rest_manager await rest_manager.stop() @@ -69,7 +70,7 @@ async def test_api_key_disabled(rest_manager, api_port): @pytest.mark.api_key('0' * 32) async def test_api_key_success(rest_manager, api_port): - api_key = rest_manager.config.key + api_key = rest_manager.config.api.key await do_real_request(api_port, 'settings?apikey=' + api_key) await do_real_request(api_port, 'settings', headers={'X-Api-Key': api_key})