diff --git a/tests/conftest.py b/tests/conftest.py index c4656cb7..81176c7e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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: diff --git a/tests/unit/test_endpoints.py b/tests/unit/test_endpoints.py new file mode 100644 index 00000000..0ca4f7b0 --- /dev/null +++ b/tests/unit/test_endpoints.py @@ -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"