generated from coulomb/repo-seed
Start Core Hub FastAPI replacement foundation
This commit is contained in:
22
tests/conftest.py
Normal file
22
tests/conftest.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import pytest
|
||||
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
|
||||
|
||||
import core_hub.models # noqa: F401
|
||||
from core_hub.app import create_app
|
||||
from core_hub.db import Base
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def app():
|
||||
return create_app()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def sqlite_engine() -> AsyncEngine:
|
||||
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
|
||||
async with engine.begin() as connection:
|
||||
await connection.run_sync(Base.metadata.create_all)
|
||||
try:
|
||||
yield engine
|
||||
finally:
|
||||
await engine.dispose()
|
||||
55
tests/test_api_v2.py
Normal file
55
tests/test_api_v2.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
PUBLIC_ENDPOINTS = [
|
||||
"/api/v2/hubs",
|
||||
"/api/v2/hub-capability-manifests",
|
||||
"/api/v2/widget-types",
|
||||
"/api/v2/event-types",
|
||||
"/api/v2/annotation-categories",
|
||||
"/api/v2/policy-scopes",
|
||||
"/api/v2/openapi.json",
|
||||
"/api/v2/openapi.yaml",
|
||||
]
|
||||
|
||||
PROTECTED_ENDPOINTS = [
|
||||
"/api/v2/api-consumers",
|
||||
"/api/v2/widgets",
|
||||
"/api/v2/interaction-events",
|
||||
"/api/v2/annotations",
|
||||
"/api/v2/requirement-candidates",
|
||||
"/api/v2/decision-records",
|
||||
"/api/v2/deployment-records",
|
||||
"/api/v2/outcome-signals",
|
||||
"/api/v2/hub-registry",
|
||||
]
|
||||
|
||||
|
||||
def test_public_api_v2_endpoints_respond(app):
|
||||
client = TestClient(app)
|
||||
|
||||
for endpoint in PUBLIC_ENDPOINTS:
|
||||
response = client.get(endpoint)
|
||||
assert response.status_code == 200, endpoint
|
||||
|
||||
|
||||
def test_hubs_seed_core_hub(app):
|
||||
response = TestClient(app).get("/api/v2/hubs")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()[0]["slug"] == "core-hub"
|
||||
|
||||
|
||||
def test_protected_api_v2_endpoints_fail_before_business_logic(app):
|
||||
client = TestClient(app)
|
||||
|
||||
for endpoint in PROTECTED_ENDPOINTS:
|
||||
response = client.get(endpoint)
|
||||
assert response.status_code == 401, endpoint
|
||||
assert response.json()["detail"]["code"] == "unauthorized"
|
||||
|
||||
|
||||
def test_openapi_contains_compatibility_routes(app):
|
||||
payload = TestClient(app).get("/api/v2/openapi.json").json()
|
||||
|
||||
assert "/api/v2/hubs" in payload["paths"]
|
||||
assert "/api/v2/widgets" in payload["paths"]
|
||||
17
tests/test_database.py
Normal file
17
tests/test_database.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from sqlalchemy import inspect
|
||||
|
||||
import core_hub.models # noqa: F401
|
||||
from core_hub.db import Base
|
||||
|
||||
|
||||
def test_metadata_contains_foundation_tables():
|
||||
assert {"hubs", "hub_capability_manifests", "api_consumers"}.issubset(Base.metadata.tables)
|
||||
|
||||
|
||||
async def test_sqlite_fixture_creates_foundation_tables(sqlite_engine):
|
||||
async with sqlite_engine.connect() as connection:
|
||||
table_names = await connection.run_sync(
|
||||
lambda sync_conn: inspect(sync_conn).get_table_names()
|
||||
)
|
||||
|
||||
assert {"hubs", "hub_capability_manifests", "api_consumers"}.issubset(table_names)
|
||||
16
tests/test_health.py
Normal file
16
tests/test_health.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_healthz(app):
|
||||
response = TestClient(app).get("/healthz")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "ok"
|
||||
assert response.json()["service"] == "core-hub"
|
||||
|
||||
|
||||
def test_readyz(app):
|
||||
response = TestClient(app).get("/readyz")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["checks"]["database_url"] == "configured"
|
||||
Reference in New Issue
Block a user