Skip to content

Commit

Permalink
add docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
sierra-moxon committed Oct 19, 2023
1 parent a23abe9 commit d118984
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
16 changes: 10 additions & 6 deletions app/routers/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Model API router."""

import logging
import requests
from typing import List

import requests
from fastapi import APIRouter, Path, Query
from oaklib.implementations.sparql.sparql_implementation import SparqlImplementation
from oaklib.resource import OntologyResource
Expand Down Expand Up @@ -513,24 +513,28 @@ async def get_pmid_by_model_id(
return collated_results


@router.get("/api/go-cam/{id}",
tags=["models"],
description="Returns model details based on a GO-CAM model ID in JSON format.")
@router.get(
"/api/go-cam/{id}", tags=["models"], description="Returns model details based on a GO-CAM model ID in JSON format."
)
async def get_model_details_by_model_id_json(
id: str = Path(
...,
description="A GO-CAM identifier (e.g. 581e072c00000820, 581e072c00000295, 5900dc7400000968)",
example="581e072c00000295",
)
):
"""
Returns model details based on a GO-CAM model ID in JSON format.
:param id: A GO-CAM identifier (e.g. 581e072c00000820, 581e072c00000295, 5900dc7400000968)
:return: model details based on a GO-CAM model ID in JSON format from the S3 bucket.
"""
path_to_s3 = "https://go-public.s3.amazonaws.com/files/go-cam/%s.json" % id
response = requests.get(path_to_s3)
response.raise_for_status() # This will raise an HTTPError if the HTTP request returned an unsuccessful status code
return response.json()




@router.get("/api/models/{id}", tags=["models"], description="Returns model details based on a GO-CAM model ID.")
async def get_term_details_by_model_id(
id: str = Path(
Expand Down
4 changes: 1 addition & 3 deletions app/routers/ribbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ async def get_subset_by_id(
description="Fetch the summary of annotations for a given gene or set of genes.",
)
async def get_ribbon_results(
subset: str = Query(None,
description="Name of the subset to map GO terms (e.g. goslim_agr)",
example="goslim_agr"),
subset: str = Query(None, description="Name of the subset to map GO terms (e.g. goslim_agr)", example="goslim_agr"),
subject: List[str] = Query(
None,
description="List of Gene ids (e.g. MGI:98214, RGD:620474)",
Expand Down
22 changes: 19 additions & 3 deletions tests/unit/test_models_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import logging
import unittest
from unittest import skip
from pprint import pprint
from unittest import skip

from fastapi.testclient import TestClient
from requests import HTTPError

Expand All @@ -14,7 +15,12 @@

test_client = TestClient(app)
gene_ids = ["ZFIN:ZDB-GENE-980526-388", "ZFIN:ZDB-GENE-990415-8", "MGI:3588192"]
go_cam_ids = ["59a6110e00000067", "SYNGO_369", "581e072c00000820", ]
go_cam_ids = [
"59a6110e00000067",
"SYNGO_369",
"581e072c00000820",
]


class TestApp(unittest.TestCase):

Expand Down Expand Up @@ -124,15 +130,25 @@ def test_get_pmid_by_model_id(self):
self.assertIn("sources", response.json()[0])

def test_get_model_details_by_model_id_json(self):
"""
Test the endpoint to retrieve model details by model ID in JSON format from the S3 bucket, check for success.
:return: None
"""
for id in go_cam_ids:
response = test_client.get(f"/api/go-cam/{id}")
pprint(response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json().get("id"), "gomodel:"+id)
self.assertEqual(response.json().get("id"), "gomodel:" + id)
self.assertGreater(len(response.json().get("individuals")), 0)
self.assertGreater(len(response.json().get("facts")), 0)

def test_get_model_details_by_model_id_json_failure(self):
"""
Test the endpoint to retrieve model details by model ID that does not exist, check for failure.
:return: None
"""
with self.assertRaises(HTTPError):
test_client.get("/api/go-cam/notatallrelevant")

Expand Down

0 comments on commit d118984

Please sign in to comment.