Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNT] Remove trailing slashes from all paths + rename NB_FAPI_ROOT_PATH #157

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
alyssadai marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

# Federation API

![GitHub branch check runs](https://img.shields.io/github/check-runs/neurobagel/federation-api/main?style=flat-square)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/neurobagel/federation-api/test.yaml?branch=main&style=flat-square&label=tests&link=https%3A%2F%2Fgithub.com%2Fneurobagel%2Ffederation-api%2Factions%2Fworkflows%2Ftest.yaml)
![Codecov](https://img.shields.io/codecov/c/github/neurobagel/federation-api?token=B827PI9W1U&style=flat-square&logo=codecov&link=https%3A%2F%2Fcodecov.io%2Fgh%2Fneurobagel%2Ffederation-api)
![Static Badge](https://img.shields.io/badge/python-3.10-blue?style=flat-square&logo=python)
![GitHub License](https://img.shields.io/github/license/neurobagel/federation-api?style=flat-square&color=purple&link=LICENSE)
![Docker Image Version (tag)](https://img.shields.io/docker/v/neurobagel/federation_api/latest?style=flat-square&logo=docker&link=https%3A%2F%2Fhub.docker.com%2Fr%2Fneurobagel%2Ffederation_api%2Ftags)
![Docker Pulls](https://img.shields.io/docker/pulls/neurobagel/federation_api?style=flat-square&logo=docker&link=https%3A%2F%2Fhub.docker.com%2Fr%2Fneurobagel%2Ffederation_api%2Ftags)
[![Main branch check status](https://img.shields.io/github/check-runs/neurobagel/federation-api/main?style=flat-square)](https://github.com/neurobagel/federation-api/actions?query=branch:main)
[![Tests status](https://img.shields.io/github/actions/workflow/status/neurobagel/federation-api/test.yaml?branch=main&style=flat-square&label=tests&link=https%3A%2F%2Fgithub.com%2Fneurobagel%2Ffederation-api%2Factions%2Fworkflows%2Ftest.yaml)](https://github.com/neurobagel/federation-api/actions/workflows/test.yaml)
[![Codecov](https://img.shields.io/codecov/c/github/neurobagel/federation-api?token=B827PI9W1U&style=flat-square&logo=codecov&link=https%3A%2F%2Fcodecov.io%2Fgh%2Fneurobagel%2Ffederation-api)](https://app.codecov.io/gh/neurobagel/federation-api)
[![Python versions static](https://img.shields.io/badge/python-3.10-blue?style=flat-square&logo=python)](https://www.python.org)
[![License](https://img.shields.io/github/license/neurobagel/federation-api?style=flat-square&color=purple&link=LICENSE)](LICENSE)
[![Docker Image Version (tag)](https://img.shields.io/docker/v/neurobagel/federation_api/latest?style=flat-square&logo=docker&link=https%3A%2F%2Fhub.docker.com%2Fr%2Fneurobagel%2Ffederation_api%2Ftags)](https://hub.docker.com/r/neurobagel/federation_api/tags)
[![Docker Pulls](https://img.shields.io/docker/pulls/neurobagel/federation_api?style=flat-square&logo=docker&link=https%3A%2F%2Fhub.docker.com%2Fr%2Fneurobagel%2Ffederation_api%2Ftags)](https://hub.docker.com/r/neurobagel/federation_api/tags)

</div>

Expand Down
2 changes: 1 addition & 1 deletion app/api/routers/assessments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
router = APIRouter(prefix="/assessments", tags=["assessments"])

router.add_api_route(
path="/",
path="",
endpoint=route_factory.create_get_instances_handler(
attributes_base_path="assessments"
),
Expand Down
2 changes: 1 addition & 1 deletion app/api/routers/diagnoses.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
router = APIRouter(prefix="/diagnoses", tags=["diagnoses"])

router.add_api_route(
path="/",
path="",
endpoint=route_factory.create_get_instances_handler(
attributes_base_path="diagnoses"
),
Expand Down
2 changes: 1 addition & 1 deletion app/api/routers/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
router = APIRouter(prefix="/pipelines", tags=["pipelines"])

router.add_api_route(
path="/",
path="",
endpoint=route_factory.create_get_instances_handler(
attributes_base_path="pipelines"
),
Expand Down
4 changes: 2 additions & 2 deletions app/api/routers/route_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# (less relevant for now since there is only one response model).
def create_get_instances_handler(attributes_base_path: str):
"""
Create the handler (path function) for a federated GET request to the root `/` subpath of
a given attribute router, e.g. /assesssments/.
Create the handler (path function) for a federated GET request to the base subpath of
a given attribute router, e.g. /assesssments.
"""

async def get_instances(response: Response):
Expand Down
2 changes: 1 addition & 1 deletion app/api/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
EnvVar = namedtuple("EnvVar", ["name", "value"])

ROOT_PATH = EnvVar(
"NB_FAPI_ROOT_PATH", os.environ.get("NB_FAPI_ROOT_PATH", "")
"NB_FAPI_BASE_PATH", os.environ.get("NB_FAPI_BASE_PATH", "")
)
IS_FEDERATE_REMOTE_PUBLIC_NODES = EnvVar(
"NB_FEDERATE_REMOTE_PUBLIC_NODES",
Expand Down
12 changes: 6 additions & 6 deletions tests/test_attribute_factory_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def test_get_instances_with_duplicate_terms_handled(
test_app, monkeypatch, set_valid_test_federation_nodes
):
"""
When multiple nodes return an assessment with the same URI for a request to /assessments/,
When multiple nodes return an assessment with the same URI for a request to /assessments,
the API should return only one instance of that assessment term in the final federated response.
"""

Expand Down Expand Up @@ -42,7 +42,7 @@ async def mock_httpx_get(self, **kwargs):

monkeypatch.setattr(httpx.AsyncClient, "get", mock_httpx_get)

response = test_app.get("/assessments/")
response = test_app.get("/assessments")

response_object = response.json()
found_instances = response_object["responses"]["nb:Assessment"]
Expand All @@ -66,7 +66,7 @@ def test_partially_failed_get_instances_handled_gracefully(
test_app, monkeypatch, set_valid_test_federation_nodes, caplog
):
"""
When some nodes fail while getting term instances for an attribute (/assessments/),
When some nodes fail while getting term instances for an attribute (/assessments),
the overall API get request still succeeds, and the response includes a list of the encountered errors along with the successfully fetched terms.
"""
mocked_node_get_assessments_response = {
Expand Down Expand Up @@ -94,7 +94,7 @@ async def mock_httpx_get(self, **kwargs):

monkeypatch.setattr(httpx.AsyncClient, "get", mock_httpx_get)

response = test_app.get("/assessments/")
response = test_app.get("/assessments")

assert response.status_code == status.HTTP_207_MULTI_STATUS

Expand All @@ -120,14 +120,14 @@ def test_fully_failed_get_instances_handled_gracefully(
caplog,
):
"""
When *all* nodes fail while getting term instances for an attribute (/assessments/),
When *all* nodes fail while getting term instances for an attribute (/assessments),
the overall API get request still succeeds, but includes an overall failure status and all encountered errors in the response.
"""
monkeypatch.setattr(
httpx.AsyncClient, "get", mock_failed_connection_httpx_get
)

response = test_app.get("/assessments/")
response = test_app.get("/assessments")

assert response.status_code == status.HTTP_207_MULTI_STATUS
# We expect several warnings from logging
Expand Down
8 changes: 7 additions & 1 deletion tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ async def mock_httpx_get(self, **kwargs):

@pytest.mark.parametrize(
"invalid_route",
["/query/", "/query/?min_age=20", "/nodes/", "/attributes/nb:SomeClass/"],
[
"/query/",
"/query/?min_age=20",
"/nodes/",
"/attributes/",
"/assessments/",
],
)
def test_request_including_trailing_slash_fails(
test_app, disable_auth, invalid_route
Expand Down
Loading