-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Add
/pipelines
router & route for fetching available pipeline…
… versions (#350) * create sparql query * add new GET route for fetching pipeline vers * rename graph response unpacking util * test new endpoint * refactor pipeline routes into separate router * update docstring
- Loading branch information
Showing
6 changed files
with
89 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,28 @@ | ||
from fastapi import APIRouter | ||
from pydantic import constr | ||
|
||
from .. import crud | ||
from .. import utility as util | ||
from ..models import CONTROLLED_TERM_REGEX | ||
|
||
router = APIRouter(prefix="/pipelines", tags=["pipelines"]) | ||
|
||
|
||
@router.get("/{pipeline_term}/versions") | ||
async def get_pipeline_versions( | ||
pipeline_term: constr(regex=CONTROLLED_TERM_REGEX), | ||
): | ||
""" | ||
When a GET request is sent, return a dict keyed on the specified pipeline resource, where the value is | ||
list of pipeline versions available in the graph for that pipeline. | ||
""" | ||
results = crud.post_query_to_graph( | ||
util.create_pipeline_versions_query(pipeline_term) | ||
) | ||
results_dict = { | ||
pipeline_term: [ | ||
res["pipeline_version"] | ||
for res in util.unpack_graph_response_json_to_dicts(results) | ||
] | ||
} | ||
return results_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,39 @@ | ||
from app.api import crud | ||
|
||
BASE_ROUTE = "/pipelines" | ||
|
||
|
||
def test_get_pipeline_versions_response( | ||
test_app, monkeypatch, set_test_credentials | ||
): | ||
""" | ||
Given a request to /pipelines/{pipeline_term}/versions with a valid pipeline name, | ||
returns a dict where the key is the pipeline resource and the value is a list of pipeline versions. | ||
""" | ||
|
||
def mock_post_query_to_graph(query, timeout=5.0): | ||
return { | ||
"head": {"vars": ["pipeline_version"]}, | ||
"results": { | ||
"bindings": [ | ||
{ | ||
"pipeline_version": { | ||
"type": "literal", | ||
"value": "23.1.3", | ||
} | ||
}, | ||
{ | ||
"pipeline_version": { | ||
"type": "literal", | ||
"value": "20.2.7", | ||
} | ||
}, | ||
] | ||
}, | ||
} | ||
|
||
monkeypatch.setattr(crud, "post_query_to_graph", mock_post_query_to_graph) | ||
|
||
response = test_app.get(f"{BASE_ROUTE}/np:fmriprep/versions") | ||
assert response.status_code == 200 | ||
assert response.json() == {"np:fmriprep": ["23.1.3", "20.2.7"]} |
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