-
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.
Merge pull request #73 from TheJacksonLaboratory/G3-270-search-endpoint
G3-270 search endpoint
- Loading branch information
Showing
6 changed files
with
127 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "geneweaver-api" | ||
version = "0.7.0a1" | ||
version = "0.7.0a2" | ||
description = "The Geneweaver API" | ||
authors = [ | ||
"Alexander Berger <[email protected]>", | ||
|
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 +1,71 @@ | ||
"""Endpoints related to searching.""" | ||
|
||
from typing import List, Optional | ||
|
||
from fastapi import APIRouter, Depends, Query, Security | ||
from geneweaver.api import dependencies as deps | ||
from geneweaver.api.schemas.apimodels import GsPubSearchType, SeachResponse | ||
from geneweaver.api.schemas.auth import UserInternal | ||
from geneweaver.api.services import geneset as genset_service | ||
from geneweaver.api.services import publications as publication_service | ||
from typing_extensions import Annotated | ||
|
||
from . import message as api_message | ||
|
||
router = APIRouter(prefix="/search", tags=["search"]) | ||
|
||
|
||
@router.get("") | ||
def search( | ||
entities: Annotated[ | ||
List[GsPubSearchType], Query(description=api_message.GS_PUB_SEARCH_TEXT) | ||
], | ||
search_text: Annotated[str, Query(description=api_message.SEARCH_TEXT)], | ||
user: UserInternal = Security(deps.optional_full_user), | ||
cursor: Optional[deps.Cursor] = Depends(deps.cursor), | ||
limit: Annotated[ | ||
Optional[int], | ||
Query( | ||
format="int64", | ||
minimum=0, | ||
maxiumum=1000, | ||
description=api_message.LIMIT, | ||
), | ||
] = 10, | ||
offset: Annotated[ | ||
Optional[int], | ||
Query( | ||
format="int64", | ||
minimum=0, | ||
maxiumum=9223372036854775807, | ||
description=api_message.OFFSET, | ||
), | ||
] = None, | ||
) -> SeachResponse: | ||
"""Search genesets and publications.""" | ||
data = {} | ||
response = SeachResponse(data=data) | ||
if "genesets" in entities: | ||
geneset_response = genset_service.get_visible_genesets( | ||
cursor=cursor, | ||
user=user, | ||
search_text=search_text, | ||
limit=limit, | ||
offset=offset, | ||
) | ||
|
||
data["geneset"] = geneset_response.get("data") | ||
|
||
if "publications" in entities: | ||
pub_response = publication_service.get( | ||
cursor, | ||
search_text=search_text, | ||
limit=limit, | ||
offset=offset, | ||
) | ||
|
||
data["publications"] = pub_response.get("data") | ||
|
||
response.data = data | ||
|
||
return response |
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,36 @@ | ||
"""Tests for search API.""" | ||
|
||
from unittest.mock import patch | ||
|
||
from tests.data import test_geneset_data, test_publication_data | ||
|
||
get_publications = test_publication_data.get("get_publications") | ||
geneset_by_id_resp = test_geneset_data.get("geneset_by_id_resp") | ||
|
||
|
||
@patch("geneweaver.api.services.publications.get") | ||
def test_pub_search(mock_pub_service_call, client): | ||
"""Test search for publications data response.""" | ||
mock_pub_service_call.return_value = get_publications | ||
|
||
response = client.get( | ||
url="/api/search/", params={"entities": "publications", "search_text": "gene"} | ||
) | ||
|
||
assert response.status_code == 200 | ||
assert response.json().get("data").get("publications") == get_publications.get( | ||
"data" | ||
) | ||
|
||
|
||
@patch("geneweaver.api.services.geneset.get_visible_genesets") | ||
def test_genesets_search_response(mock_get_visible_genesets, client): | ||
"""Test search for geneset data response.""" | ||
mock_data = geneset_by_id_resp.get("geneset") | ||
mock_get_visible_genesets.return_value = mock_data | ||
|
||
response = client.get( | ||
url="/api/search/", params={"entities": "genesets", "search_text": "gene"} | ||
) | ||
assert response.status_code == 200 | ||
assert response.json().get("data").get("genesets") == mock_data.get("data") |