-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix semsim search GET api method, add api tests (#529)
The actual fix is just swapping "category" for "group" in the semsim search GET request, but I also wanted to start on getting full test coverage of our api methods.
- Loading branch information
1 parent
90e8759
commit 388f597
Showing
4 changed files
with
204 additions
and
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,63 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from fastapi import status | ||
from unittest.mock import MagicMock, patch | ||
|
||
from monarch_py.api.additional_models import SemsimSearchGroup | ||
from monarch_py.api.semsim import router | ||
|
||
client = TestClient(router) | ||
|
||
|
||
@pytest.mark.skip(reason="Not implemented") | ||
def test_semsim(semsim): | ||
... | ||
@patch("monarch_py.api.config.SemsimianHTTPRequester.compare") | ||
def test_get_compare(mock_compare): | ||
mock_compare.return_value = MagicMock() | ||
|
||
subjects = "HP:123,HP:456" | ||
objects = "HP:789,HP:101112" | ||
|
||
response = client.get(f"/compare/{subjects}/{objects}") | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
mock_compare.assert_called_once_with(subjects=["HP:123", "HP:456"], objects=["HP:789", "HP:101112"]) | ||
|
||
|
||
@patch("monarch_py.api.config.SemsimianHTTPRequester.compare") | ||
def test_post_compare(mock_compare): | ||
mock_compare.return_value = MagicMock() | ||
|
||
subjects = ["HP:123", "HP:456"] | ||
objects = ["HP:789", "HP:101112"] | ||
|
||
response = client.post(f"/compare/", json={"subjects": subjects, "objects": objects}) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
mock_compare.assert_called_once_with(subjects=subjects, objects=objects) | ||
|
||
|
||
@patch("monarch_py.api.config.SemsimianHTTPRequester.search") | ||
@pytest.mark.parametrize("termset", ["HP:123,HP:456", "HP:123, HP:456", " HP:123, HP:456 "]) | ||
def test_get_search(mock_search, termset: str): | ||
mock_search.return_value = MagicMock() | ||
|
||
group = SemsimSearchGroup.HGNC | ||
limit = 5 | ||
|
||
response = client.get(f"/search/{termset}/{group.value}?limit={limit}") | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
mock_search.assert_called_once_with(termset=["HP:123", "HP:456"], prefix=group.name, limit=limit) | ||
|
||
|
||
@patch("monarch_py.api.config.SemsimianHTTPRequester.search") | ||
def test_post_search(mock_search): | ||
mock_search.return_value = MagicMock() | ||
|
||
termset = ["HP:123", "HP:456"] | ||
group = SemsimSearchGroup.HGNC | ||
limit = 5 | ||
|
||
response = client.post(f"/search/", json={"termset": termset, "group": group.value, "limit": limit}) | ||
|
||
assert response.status_code == status.HTTP_200_OK | ||
mock_search.assert_called_once_with(termset=["HP:123", "HP:456"], prefix=group.name, limit=limit) |