Skip to content

Commit

Permalink
Update the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
heldersepu committed May 8, 2024
1 parent 8ec65bf commit 1fc17be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}

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

Expand Down

0 comments on commit 1fc17be

Please sign in to comment.