Download tests/test_api.py from OpenVar/backend: direct link, hf CLI and curl.
- Browser
- Download file 3.66 kB
-
https://huggingface.co/spaces/OpenVar/backend/resolve/main/tests/test_api.py
- Command line
-
hf download hf://spaces/OpenVar/backend/tests/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/OpenVar/backend/resolve/main/tests/test_api.py
3.66 kB
| import pytest | |
| from fastapi.testclient import TestClient | |
| from unittest.mock import patch, AsyncMock | |
| from app.main import app | |
| client = TestClient(app) | |
| class TestHealthEndpoint: | |
| def test_root(self): | |
| response = client.get("/") | |
| assert response.status_code == 200 | |
| assert response.json()["message"] == "OpenVar API" | |
| def test_health(self): | |
| response = client.get("/health") | |
| assert response.status_code == 200 | |
| assert response.json()["status"] == "healthy" | |
| class TestGenesAPI: | |
| def test_list_genes(self): | |
| response = client.get("/api/genes") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert isinstance(data, list) | |
| assert len(data) > 0 | |
| assert data[0]["symbol"] == "BRCA1" | |
| def test_list_genes_with_query(self): | |
| response = client.get("/api/genes?query=BRCA") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert all("BRCA" in gene["symbol"] for gene in data) | |
| def test_list_genes_limit_validation(self): | |
| response = client.get("/api/genes?limit=1000") | |
| assert response.status_code == 422 | |
| def test_get_gene(self): | |
| response = client.get("/api/genes/BRCA1") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert data["symbol"] == "BRCA1" | |
| def test_get_gene_not_found(self): | |
| response = client.get("/api/genes/UNKNOWN") | |
| assert response.status_code == 404 | |
| class TestAuthAPI: | |
| def test_login_success(self): | |
| response = client.post( | |
| "/api/auth/login", | |
| json={"email": "demo@openvar.io", "password": "demo"} | |
| ) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "access_token" in data | |
| assert data["user"]["email"] == "demo@openvar.io" | |
| def test_login_invalid_credentials(self): | |
| response = client.post( | |
| "/api/auth/login", | |
| json={"email": "wrong@example.com", "password": "wrong"} | |
| ) | |
| assert response.status_code == 401 | |
| def test_get_current_user(self): | |
| response = client.get("/api/auth/me") | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert "email" in data | |
| class TestVariantAPI: | |
| def test_search_variant_coordinates(self, mock_annotate): | |
| mock_annotate.return_value = { | |
| "variant": { | |
| "id": "9-135800978-A-G", | |
| "chromosome": "9", | |
| "position": 135800978, | |
| "ref": "A", | |
| "alt": "G", | |
| "gene": "PTPRD" | |
| }, | |
| "acmg": {"classification": "Uncertain significance"} | |
| } | |
| response = client.post( | |
| "/api/variant/search", | |
| json={"query": "chr9-135800978-A-G", "genome_build": "hg38"} | |
| ) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert isinstance(data, list) | |
| def test_search_structural_variant(self): | |
| response = client.post( | |
| "/api/variant/search", | |
| json={"query": "DUP:Chr5:125423848-128107072", "genome_build": "hg38"} | |
| ) | |
| assert response.status_code == 200 | |
| data = response.json() | |
| assert len(data) == 1 | |
| assert data[0]["variant"]["id"] == "chr5-125423848-128107072-DUP-hg38" | |
| assert data[0]["consequences"]["sv_type"] == "DUP" | |
| def test_get_variant_not_found(self): | |
| response = client.get("/api/variant/invalid-variant-id") | |
| assert response.status_code == 404 | |