-
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 branch 'main' into task/fix-release-gates
- Loading branch information
Showing
15 changed files
with
637 additions
and
94 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,24 @@ | ||
"""Endpoints related to species.""" | ||
from typing import Optional | ||
|
||
from fastapi import APIRouter, Depends, Query | ||
from geneweaver.api import dependencies as deps | ||
from geneweaver.api.services import species as species_service | ||
from geneweaver.core.enum import GeneIdentifier | ||
from typing_extensions import Annotated | ||
|
||
router = APIRouter(prefix="/species", tags=["species"]) | ||
|
||
|
||
@router.get("/") | ||
def get_species( | ||
cursor: Optional[deps.Cursor] = Depends(deps.cursor), | ||
taxonomy_id: Annotated[ | ||
Optional[int], Query(format="int64", minimum=0, maxiumum=9223372036854775807) | ||
] = None, | ||
reference_gene_id_type: Optional[GeneIdentifier] = None, | ||
) -> dict: | ||
"""Get species.""" | ||
response = species_service.get_species(cursor, taxonomy_id, reference_gene_id_type) | ||
|
||
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 @@ | ||
"""Service functions for Species.""" | ||
|
||
from typing import Optional | ||
|
||
from fastapi.logger import logger | ||
from geneweaver.core.enum import GeneIdentifier | ||
from geneweaver.db import species as db_species | ||
from psycopg import Cursor | ||
|
||
|
||
def get_species( | ||
cursor: Cursor, | ||
taxonomy_id: Optional[int] = None, | ||
reference_gene_id_type: Optional[GeneIdentifier] = None, | ||
) -> dict: | ||
"""Get species from DB. | ||
@param cursor: DB cursor | ||
@param taxonomy_id: | ||
@param reference_gene_id_type: | ||
@return: dictionary response (species). | ||
""" | ||
try: | ||
species = db_species.get(cursor, taxonomy_id, reference_gene_id_type) | ||
for species_record in species: | ||
ref_gene_id_type = species_record.get("reference_gene_identifier", None) | ||
if ref_gene_id_type: | ||
species_record["reference_gene_identifier"] = GeneIdentifier( | ||
ref_gene_id_type | ||
) | ||
|
||
return {"species": species} | ||
|
||
except Exception as err: | ||
logger.error(err) | ||
raise err |
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,43 @@ | ||
"""Tests for species API.""" | ||
from unittest.mock import patch | ||
|
||
from tests.data import test_species_data | ||
|
||
species_no_params = test_species_data.get("species_no_parameters") | ||
species_by_taxonomy_id_10090 = test_species_data.get("species_by_taxonomy_id_10090") | ||
species_by_gene_id_type_flybase = test_species_data.get( | ||
"species_by_gene_id_type_flybase" | ||
) | ||
|
||
|
||
@patch("geneweaver.api.services.species.get_species") | ||
def test_valid_species_url_req(mock_species_service_call, client): | ||
"""Test valid url request to get species.""" | ||
mock_species_service_call.return_value = species_no_params | ||
|
||
response = client.get(url="/api/species") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == species_no_params | ||
|
||
|
||
@patch("geneweaver.api.services.species.get_species") | ||
def test_species_url_taxonomy_req(mock_species_service_call, client): | ||
"""Test valid url request to get species.""" | ||
mock_species_service_call.return_value = species_by_taxonomy_id_10090 | ||
|
||
response = client.get(url="/api/species?taxonomy_id=10090") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == species_by_taxonomy_id_10090 | ||
|
||
|
||
@patch("geneweaver.api.services.species.get_species") | ||
def test_valid_species_url_gene_id_type_req(mock_species_service_call, client): | ||
"""Test valid url request to get species.""" | ||
mock_species_service_call.return_value = species_by_gene_id_type_flybase | ||
|
||
response = client.get(url="/api/species?gene_id_type=14") | ||
|
||
assert response.status_code == 200 | ||
assert response.json() == species_by_gene_id_type_flybase |
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
Oops, something went wrong.