-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Add route for fetching available versions of a pipeline across …
…n-APIs (#125) * make query params optional in n-API request, & create CRUD func for fetching pipeline vers * add pipelines router with endpoint for fetching versions * test new endpoint * add TODO
- Loading branch information
Showing
5 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from fastapi import APIRouter, Response, status | ||
from pydantic import constr | ||
|
||
from .. import crud | ||
from ..models import CONTROLLED_TERM_REGEX, CombinedAttributeResponse | ||
|
||
router = APIRouter(prefix="/pipelines", tags=["pipelines"]) | ||
|
||
|
||
@router.get( | ||
"/{pipeline_term}/versions", response_model=CombinedAttributeResponse | ||
) | ||
async def get_pipeline_versions( | ||
pipeline_term: constr(regex=CONTROLLED_TERM_REGEX), response: Response | ||
): | ||
""" | ||
When a GET request is sent, return a dict where the key is the pipeline term and the value | ||
is a list containing all available versions of a pipeline, across all nodes known to the f-API. | ||
""" | ||
response_dict = await crud.get_pipeline_versions(pipeline_term) | ||
|
||
if response_dict["errors"]: | ||
response.status_code = status.HTTP_207_MULTI_STATUS | ||
|
||
return response_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import httpx | ||
from fastapi import status | ||
|
||
|
||
def test_unique_pipeline_versions_returned_from_nodes( | ||
test_app, monkeypatch, set_valid_test_federation_nodes | ||
): | ||
""" | ||
Test that given a successful request to two nodes for versions of a specific pipeline term, | ||
the API correctly returns a list of unique versions across both nodes. | ||
""" | ||
|
||
# Predefine the responses from the mocked n-APIs set using the fixture set_valid_test_federation_nodes | ||
async def mock_httpx_get(self, **kwargs): | ||
if "https://firstpublicnode.org/" in kwargs["url"]: | ||
mocked_response_json = {"np:pipeline1": ["1.0.0", "1.0.1"]} | ||
else: | ||
mocked_response_json = {"np:pipeline1": ["1.0.1", "1.0.2"]} | ||
return httpx.Response( | ||
status_code=200, | ||
json=mocked_response_json, | ||
) | ||
|
||
monkeypatch.setattr(httpx.AsyncClient, "get", mock_httpx_get) | ||
|
||
response = test_app.get("/pipelines/np:pipeline1/versions") | ||
assert response.status_code == status.HTTP_200_OK | ||
|
||
response_object = response.json() | ||
assert len(response_object["errors"]) == 0 | ||
assert response_object["responses"] == { | ||
"np:pipeline1": ["1.0.0", "1.0.1", "1.0.2"] | ||
} | ||
assert response_object["nodes_response_status"] == "success" |