Skip to content

Commit

Permalink
Merge pull request #49 from TheJacksonLaboratory/G3-212-genes-endpoin…
Browse files Browse the repository at this point in the history
…t-return-schema

G3 212 genes endpoint return schema
  • Loading branch information
francastell authored Apr 5, 2024
2 parents 8b0680b + d66e174 commit 27e7d3c
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geneweaver-api"
version = "0.4.0a9"
version = "0.4.0a11"
description = "The Geneweaver API"
authors = [
"Alexander Berger <[email protected]>",
Expand Down
6 changes: 4 additions & 2 deletions src/geneweaver/api/controller/genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
GeneIdMappingAonReq,
GeneIdMappingReq,
GeneIdMappingResp,
GeneReturn,
)
from geneweaver.api.services import genes as genes_service
from geneweaver.core.enum import GeneIdentifier, Species
from geneweaver.core.schema.gene import Gene
from typing_extensions import Annotated

from . import message as api_message
Expand Down Expand Up @@ -48,7 +50,7 @@ def get_genes(
description=api_message.OFFSET,
),
] = None,
) -> dict:
) -> GeneReturn:
"""Get geneweaver list of genes."""
if limit is None:
limit = 100
Expand All @@ -65,7 +67,7 @@ def get_gene_preferred(
int, Path(format="int64", minimum=0, maxiumum=9223372036854775807)
],
cursor: Optional[deps.Cursor] = Depends(deps.cursor),
) -> dict:
) -> Gene:
"""Get preferred gene for a given gene ode_id."""
response = genes_service.get_gene_preferred(cursor, gene_id)
return response
Expand Down
7 changes: 7 additions & 0 deletions src/geneweaver/api/schemas/apimodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import Iterable, List, Optional

from geneweaver.core.enum import GeneIdentifier, Species
from geneweaver.core.schema.gene import Gene
from pydantic import BaseModel


Expand Down Expand Up @@ -35,3 +36,9 @@ class GeneIdMappingAonReq(BaseModel):

source_ids: List[str]
species: Species


class GeneReturn(BaseModel):
"""Model for gene endpoint return."""

data: List[Gene]
4 changes: 2 additions & 2 deletions src/geneweaver/api/services/genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_genes(
logger.error(err)
raise err

return {"genes": gene_list}
return {"data": gene_list}


def get_gene_preferred(cursor: Cursor, gene_id: int) -> dict:
Expand All @@ -56,7 +56,7 @@ def get_gene_preferred(cursor: Cursor, gene_id: int) -> dict:
logger.error(err)
raise err

return {"gene": gene}
return gene


def get_homolog_ids(
Expand Down
12 changes: 5 additions & 7 deletions tests/controllers/test_genes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_gene_id_mapping_response_post_req(mock_gene_id_mapping, client):
response = client.post(
url="/api/genes/homologs", data=json.dumps(gene_ids_homolog_req_1)
)
print(response)

assert response.status_code == 200
assert response.json() == gene_ids_homolog_resp_1

Expand All @@ -47,7 +47,7 @@ def test_gene_id_mapping_invalid_url(mock_gene_id_mapping, client):
response = client.post(
url="/api/genes/homologous-ids", data=json.dumps(gene_ids_homolog_req_1)
)
print(response)

assert response.status_code == 404


Expand Down Expand Up @@ -98,7 +98,7 @@ def test_gene_mapping_valid_post_req(mock_gene_id_mapping, client):
response = client.post(
url="/api/genes/mappings", data=json.dumps(gene_id_mapping_req_1)
)
print(response)

assert response.status_code == 200
assert response.json() == gene_id_mapping_resp_1

Expand All @@ -113,7 +113,7 @@ def test_gene_mapping_invalid_url(mock_gene_id_mapping, client):
response = client.post(
url="/api/genes/mapping", data=json.dumps(gene_id_mapping_req_1)
)
print(response)

assert response.status_code == 404


Expand All @@ -138,7 +138,7 @@ def test_gene_aon_mapping_valid_post_req(mock_gene_id_aon_mapping, client):
response = client.post(
url="/api/genes/mappings/aon", data=json.dumps(gene_id_aon_mapping_req_1)
)
print(response)

assert response.status_code == 200
assert response.json() == gene_id_aon_mapping_resp_1

Expand All @@ -158,7 +158,6 @@ def test_valid_gene_get_req(mock_gene_call, client):

response = client.get(url="/api/genes")

print(response)
assert response.status_code == 200
assert response.json() == genes_list_10

Expand Down Expand Up @@ -188,7 +187,6 @@ def test_invalid_param_gene_get_req(mock_gene_call, client):
def test_valid_get_preferred_gene_req(mock_gene_call, client):
"""Test valid get preferred gene request."""
mock_gene_call.return_value = gene_preferred_resp_1

response = client.get(url="/api/genes/1000/preferred")

assert response.status_code == 200
Expand Down
48 changes: 23 additions & 25 deletions tests/data/genes.json
Original file line number Diff line number Diff line change
@@ -1,96 +1,94 @@
{
"genes_list_10": {
"genes": [
"data": [
{
"id": 1,
"reference_id": "MGI:87853",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 2,
"reference_id": "MGI:87854",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 3,
"reference_id": "MGI:87859",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 4,
"reference_id": "MGI:87860",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 5,
"reference_id": "MGI:87862",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 6,
"reference_id": "MGI:87863",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 7,
"reference_id": "MGI:87864",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 8,
"reference_id": "MGI:87866",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 9,
"reference_id": "MGI:87867",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
},
{
"id": 10,
"reference_id": "MGI:87868",
"gene_database": 10,
"species": 1,
"gene_database": "MGI",
"species": "Mus Musculus",
"preferred": false,
"date": "2020-05-05"
}
]
},
"gene_preferred_resp_1": {
"gene": {
"id": 1000,
"reference_id": "Il1r2",
"gene_database": 7,
"species": 1,
"gene_database": "Gene Symbol",
"species": "Mus Musculus",
"preferred": true,
"date": "2020-05-05"
}
}
}
6 changes: 3 additions & 3 deletions tests/services/test_gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def test_get_gene_error(mock_db_gene):
mock_db_gene.get.side_effect = Exception("ERROR")

with pytest.raises(expected_exception=Exception):
genes.get(None)
genes.get_genes(None)


@patch("geneweaver.api.services.genes.db_gene")
Expand All @@ -242,7 +242,7 @@ def test_get_gene(mock_db_gene):
response = genes.get_genes(None)

assert response.get("error") is None
assert response.get("genes") == genes_list_10
assert response.get("data") == genes_list_10

response = genes.get_genes(
None,
Expand All @@ -265,7 +265,7 @@ def test_get_gene_preferred(mock_db_gene):
response = genes.get_gene_preferred(None, gene_id=1000)

assert response.get("error") is None
assert response.get("gene") == gene_preferred_resp_1
assert response == gene_preferred_resp_1


@patch("geneweaver.api.services.genes.db_gene")
Expand Down

0 comments on commit 27e7d3c

Please sign in to comment.