Skip to content

Commit

Permalink
test: add basic route tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Nov 7, 2023
1 parent 8eb2bfb commit 9f6c5de
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def pytest_collection_modifyitems(items):
"test_merge",
"test_database",
"test_query",
"test_endpoints",
"test_emit_warnings",
]
# remember to add new test modules to the order constant:
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/test_endpoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Perform basic tests of endpoint branches.
We already have tests and data validation to ensure correctness of the underlying
response objects -- here, we're checking for bad branch logic and for basic assurances
that routes integrate correctly with query methods.
"""
import pytest
from fastapi.testclient import TestClient

from disease.main import app


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


def test_search(api_client):
"""Test /search endpoint."""
response = api_client.get("/disease/search?q=neuroblastoma")
assert response.status_code == 200
assert (
response.json()["source_matches"]["Mondo"]["records"][0]["concept_id"]
== "mondo:0005072"
)

response = api_client.get("/disease/search?q=neuroblastoma&incl=sdkl")
assert response.status_code == 422


def test_normalize(api_client):
"""Test /normalize endpoint."""
response = api_client.get("/disease/normalize?q=neuroblastoma")
assert response.status_code == 200
assert response.json()["normalized_id"] == "ncit:C3270"


def test_normalize_unmerged(api_client):
"""Test /normalize_unmerged endpoint."""
response = api_client.get("/disease/normalize_unmerged?q=neuroblastoma")
assert response.status_code == 200
assert response.json()["normalized_concept_id"] == "ncit:C3270"

0 comments on commit 9f6c5de

Please sign in to comment.