Skip to content

Commit

Permalink
add more biolerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Jan 14, 2025
1 parent bb680ed commit 1b842d0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/gene/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ async def lifespan(app: FastAPI) -> AsyncGenerator:
def search(
request: Request,
q: Annotated[str, Query(..., description=q_descr)],
incl: Annotated[str | None, Query(None, description=incl_descr)],
excl: Annotated[str | None, Query(None, description=excl_descr)],
incl: Annotated[str | None, Query(description=incl_descr)] = None,
excl: Annotated[str | None, Query(description=excl_descr)] = None,
) -> SearchService:
"""Return strongest match concepts to query string provided by user.
Expand Down Expand Up @@ -192,7 +192,7 @@ def normalize_unmerged(


@app.get(
"/service_info",
"/gene/service_info",
summary="Get basic service information",
description="Retrieve service metadata, such as versioning and contact info. Structured in conformance with the [GA4GH service info API specification](https://www.ga4gh.org/product/service-info/)",
tags=[_Tag.META],
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Test FastAPI endpoint function."""

import re
from datetime import datetime

import pytest
from fastapi.testclient import TestClient

from gene.main import app


@pytest.fixture(scope="module")
def api_client():
"""Provide test API client"""
return TestClient(app)


def test_service_info(api_client: TestClient):
"""Test /service_info endpoint"""
response = api_client.get("/gene/service_info")
assert response.status_code == 200
expected_version_pattern = r"\d\.\d\."
response_json = response.json()
assert response_json["id"] == "org.genomicmedlab.gene-normalizer"
assert response_json["name"] == "Gene Normalizer"
assert response_json["type"]["group"] == "org.genomicmedlab"
assert response_json["type"]["artifact"] == "Gene Normalizer API"
assert re.match(expected_version_pattern, response_json["type"]["version"])
assert (
response_json["description"]
== "Tools for resolving ambiguous gene symbols to richly-annotated concepts"
)
assert response_json["organization"] == {
"name": "Genomic Medicine Lab at Nationwide Children's Hospital",
"url": "https://www.nationwidechildrens.org/specialties/institute-for-genomic-medicine/research-labs/wagner-lab",
}
assert response_json["contactUrl"] == "[email protected]"
assert (
response_json["documentationUrl"] == "https://gene-normalizer.readthedocs.io/"
)
assert datetime.fromisoformat(response_json["createdAt"])
assert re.match(expected_version_pattern, response_json["version"])

0 comments on commit 1b842d0

Please sign in to comment.