Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfk committed Nov 27, 2024
1 parent b1d6104 commit 15e7be9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion bento_beacon/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions bento_beacon/network/network.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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

Check warning on line 23 in bento_beacon/network/network.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/network.py#L22-L23

Added lines #L22 - L23 were not covered by tests
Expand Down
5 changes: 2 additions & 3 deletions bento_beacon/network/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Check warning on line 162 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L162

Added line #L162 was not covered by tests

current_app.logger.info(f"registering {len(urls)} beacons")

Check warning on line 164 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L164

Added line #L164 was not covered by tests

host_beacon_url = current_app.config["BEACON_BASE_URL"]
Expand All @@ -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)]

Check warning on line 182 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L182

Added line #L182 was not covered by tests


current_app.logger.info(f"registered {len(registered_beacons)} beacon(s) in network")
num_failed = len(results) - len(registered_beacons)

Check warning on line 185 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L184-L185

Added lines #L184 - L185 were not covered by tests
if num_failed:
current_app.logger.info(f"{num_failed} beacon(s) failed to register")

Check warning on line 187 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L187

Added line #L187 was not covered by tests

# dict by beacon id easier to work with elsewhere
beacon_dict = {b["id"]: b for b in registered_beacons}

Check warning on line 190 in bento_beacon/network/utils.py

View check run for this annotation

Codecov / codecov/patch

bento_beacon/network/utils.py#L190

Added line #L190 was not covered by tests

Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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,
}

Expand Down
6 changes: 3 additions & 3 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from .conftest import (
validate_response,
token_endpoint_config_response,
TOKEN_ENDPOINT_CONFIG_RESPONSE,
)


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 15e7be9

Please sign in to comment.