From 15e7be98942abdfe9643917f4f85e3aec9ad2c39 Mon Sep 17 00:00:00 2001 From: Gordon Krieger Date: Wed, 27 Nov 2024 17:21:18 +0000 Subject: [PATCH] cleanup --- bento_beacon/app.py | 1 - bento_beacon/network/network.py | 10 +++++----- bento_beacon/network/utils.py | 5 ++--- tests/conftest.py | 4 ++-- tests/test_routes.py | 6 +++--- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/bento_beacon/app.py b/bento_beacon/app.py index 18e4639..fcc941f 100644 --- a/bento_beacon/app.py +++ b/bento_beacon/app.py @@ -11,7 +11,6 @@ from .endpoints.cohorts import cohorts from .endpoints.datasets import datasets from .network.network import network -from .network.utils import init_network_service_registry from .utils.exceptions import APIException from werkzeug.exceptions import HTTPException from .authz.middleware import authz_middleware diff --git a/bento_beacon/network/network.py b/bento_beacon/network/network.py index 2bb1c4d..93a1f66 100644 --- a/bento_beacon/network/network.py +++ b/bento_beacon/network/network.py @@ -1,5 +1,5 @@ from flask import current_app, request, Blueprint -from ..utils.exceptions import APIException, NotFoundException +from ..utils.exceptions import NotFoundException from .utils import network_beacon_get, network_beacon_post, host_beacon_response, init_network_service_registry @@ -8,16 +8,16 @@ # TODOs: # filtering terms XXXXXXXXXXXXXXXXXXXXXXXXXXX -# /service-info? there's already one at beacon root - -# standard beacon info endpoints at the network level: /map, /configuration, etc # handle GET args +# and perhaps standard beacon info endpoints at the network level: /map, /configuration, /service-info etc +# these are only useful if we plan to organize hierarchical networks +# (by e.g. adding our network as a single beacon to another network) + @network.route("") @network.route("/beacons") async def network_beacons(): - # beacons_dict = current_app.config.get("NETWORK_BEACONS") beacons_dict = await init_network_service_registry() current_app.config["NETWORK_BEACONS"] = beacons_dict diff --git a/bento_beacon/network/utils.py b/bento_beacon/network/utils.py index 7adde3f..dadb7aa 100644 --- a/bento_beacon/network/utils.py +++ b/bento_beacon/network/utils.py @@ -160,7 +160,7 @@ async def init_network_service_registry(): if not urls: current_app.logger.error("can't find urls for beacon network, did you forget a config file?") raise APIException("can't find urls for beacon network") - + current_app.logger.info(f"registering {len(urls)} beacons") host_beacon_url = current_app.config["BEACON_BASE_URL"] @@ -180,13 +180,12 @@ async def init_network_service_registry(): # filter out any failed calls registered_beacons = [b for b in results if not isinstance(b, Exception)] - current_app.logger.info(f"registered {len(registered_beacons)} beacon(s) in network") num_failed = len(results) - len(registered_beacons) if num_failed: current_app.logger.info(f"{num_failed} beacon(s) failed to register") - + # dict by beacon id easier to work with elsewhere beacon_dict = {b["id"]: b for b in registered_beacons} diff --git a/tests/conftest.py b/tests/conftest.py index 79d6968..ba40e1a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,9 +1,9 @@ +import jsonschema import os import pathlib from urllib.parse import urlunsplit from aioresponses import aioresponses from flask import current_app -import jsonschema import pytest @@ -15,7 +15,7 @@ OPENID_CONFIG_URL = AUTHZ_URL + "/fake/openid-configuration" TOKEN_URL = AUTHZ_URL + "/fake/token" -token_endpoint_config_response = { +TOKEN_ENDPOINT_CONFIG_RESPONSE = { "token_endpoint": TOKEN_URL, } diff --git a/tests/test_routes.py b/tests/test_routes.py index fba2040..6fcdb8b 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -12,7 +12,7 @@ from .conftest import ( validate_response, - token_endpoint_config_response, + TOKEN_ENDPOINT_CONFIG_RESPONSE, ) @@ -159,7 +159,7 @@ def test_individuals_query_all_permissions(app_config, client, aioresponse): katsu_public_search_url = katsu_url + app_config["KATSU_BEACON_SEARCH"] + "?" + KATSU_QUERY_PARAMS gohan_search_url = app_config["GOHAN_BASE_URL"] + app_config["GOHAN_SEARCH_ENDPOINT"] + "?" + GOHAN_QUERY_PARAMS - aioresponse.get(openid_config_url, payload=token_endpoint_config_response) + aioresponse.get(openid_config_url, payload=TOKEN_ENDPOINT_CONFIG_RESPONSE) aioresponse.post(authz_evaluate_url, payload={"result": [[True]]}) aioresponse.post(token_url, payload=token_response, repeat=True) aioresponse.post(katsu_private_search_url, payload=katsu_private_search_response) @@ -192,7 +192,7 @@ def test_individuals_query_no_permissions(app_config, client, aioresponse): gohan_search_url = app_config["GOHAN_BASE_URL"] + app_config["GOHAN_SEARCH_ENDPOINT"] + "?" + GOHAN_QUERY_PARAMS aioresponse.post(authz_evaluate_url, payload={"result": [[False]]}) - aioresponse.get(openid_config_url, payload=token_endpoint_config_response) + aioresponse.get(openid_config_url, payload=TOKEN_ENDPOINT_CONFIG_RESPONSE) aioresponse.post(token_url, payload=token_response, repeat=True) aioresponse.post(katsu_private_search_url, payload=katsu_private_search_response) aioresponse.post(katsu_search_overview_url, payload=katsu_private_search_overview_response)