-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Return dataset sizes in query response (#223)
* fix docstring * add key to CohortQueryResponse for total n in dataset * add util for constructing query for size of specific datasets * refactor out code to reformat http response * update crud function for subject query endpoint to return matching dataset sizes * update test data fixture * test new httpx response unpacking util
- Loading branch information
Showing
6 changed files
with
115 additions
and
9 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
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
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,61 @@ | ||
"""Test utility functions.""" | ||
from app.api import utility as util | ||
|
||
|
||
def test_unpack_http_response_json_to_dicts(): | ||
"""Test that given a valid httpx JSON response, the function returns a simplified list of dicts with the correct keys and values.""" | ||
mock_response_json = { | ||
"head": {"vars": ["dataset_uuid", "total_subjects"]}, | ||
"results": { | ||
"bindings": [ | ||
{ | ||
"dataset_uuid": { | ||
"type": "uri", | ||
"value": "http://neurobagel.org/vocab/ds1234", | ||
}, | ||
"total_subjects": { | ||
"datatype": "http://www.w3.org/2001/XMLSchema#integer", | ||
"type": "literal", | ||
"value": "70", | ||
}, | ||
}, | ||
{ | ||
"dataset_uuid": { | ||
"type": "uri", | ||
"value": "http://neurobagel.org/vocab/ds2345", | ||
}, | ||
"total_subjects": { | ||
"datatype": "http://www.w3.org/2001/XMLSchema#integer", | ||
"type": "literal", | ||
"value": "40", | ||
}, | ||
}, | ||
{ | ||
"dataset_uuid": { | ||
"type": "uri", | ||
"value": "http://neurobagel.org/vocab/ds3456", | ||
}, | ||
"total_subjects": { | ||
"datatype": "http://www.w3.org/2001/XMLSchema#integer", | ||
"type": "literal", | ||
"value": "84", | ||
}, | ||
}, | ||
] | ||
}, | ||
} | ||
|
||
assert util.unpack_http_response_json_to_dicts(mock_response_json) == [ | ||
{ | ||
"dataset_uuid": "http://neurobagel.org/vocab/ds1234", | ||
"total_subjects": "70", | ||
}, | ||
{ | ||
"dataset_uuid": "http://neurobagel.org/vocab/ds2345", | ||
"total_subjects": "40", | ||
}, | ||
{ | ||
"dataset_uuid": "http://neurobagel.org/vocab/ds3456", | ||
"total_subjects": "84", | ||
}, | ||
] |