Buckets:

download
raw
6.17 kB
"""Tests for Bloom-mounted TapDB admin surface."""
from __future__ import annotations
import os
from types import SimpleNamespace
from fastapi import APIRouter, FastAPI
from fastapi.testclient import TestClient
import bloom_lims.integrations.tapdb_mount as tapdb_mount
import bloom_lims.tapdb_dag as tapdb_dag
from bloom_lims.app import create_app
def _client() -> TestClient:
os.environ["BLOOM_TAPDB_MOUNT_ENABLED"] = "1"
os.environ["BLOOM_TAPDB_MOUNT_PATH"] = "/tapdb"
return TestClient(create_app(), raise_server_exceptions=False)
def _dummy_tapdb_app() -> FastAPI:
app = FastAPI()
@app.get("/")
async def _index():
return {"tapdb": "ok"}
return app
def test_mounted_route_exists_under_bloom_app():
with _client() as client:
response = client.get("/tapdb/", follow_redirects=False)
assert response.status_code != 404
def test_unauthenticated_request_redirects_to_bloom_login():
with _client() as client:
response = client.get("/tapdb/", follow_redirects=False)
assert response.status_code == 302
assert response.headers.get("location") == "/login?next=/tapdb/"
json_response = client.get(
"/tapdb/api/search",
headers={"accept": "application/json"},
follow_redirects=False,
)
assert json_response.status_code == 401
assert json_response.json()["detail"] == "host_session_required"
def test_non_admin_authenticated_user_is_denied(monkeypatch):
monkeypatch.setattr(
tapdb_mount,
"_resolve_bloom_user_data",
lambda _scope: {"email": "user@example.com", "role": "READ_WRITE"},
)
with _client() as client:
json_response = client.get(
"/tapdb/api/admin/readiness",
headers={"accept": "application/json"},
follow_redirects=False,
)
assert json_response.status_code == 403
assert json_response.json()["detail"] == "tapdb_gui_admin_required"
def test_admin_user_can_access_mounted_surface(monkeypatch):
monkeypatch.setattr(
tapdb_mount,
"_resolve_bloom_user_data",
lambda _scope: {"email": "admin@example.com", "role": "ADMIN"},
)
monkeypatch.setattr(
tapdb_mount,
"_load_tapdb_admin_app",
lambda **_kwargs: _dummy_tapdb_app(),
)
with _client() as client:
response = client.get("/tapdb/", follow_redirects=False)
assert response.status_code != 404
def test_tapdb_local_auth_not_required_in_mounted_mode(monkeypatch):
monkeypatch.setattr(
tapdb_mount,
"_resolve_bloom_user_data",
lambda _scope: {"email": "admin@example.com", "role": "ADMIN"},
)
monkeypatch.setattr(
tapdb_mount,
"_load_tapdb_admin_app",
lambda **_kwargs: _dummy_tapdb_app(),
)
with _client() as client:
response = client.get("/tapdb/", follow_redirects=False)
assert response.status_code != 404
def test_bloom_single_app_serves_api_and_tapdb_mount(monkeypatch):
monkeypatch.setattr(
tapdb_mount,
"_resolve_bloom_user_data",
lambda _scope: {"email": "admin@example.com", "role": "ADMIN"},
)
monkeypatch.setattr(
tapdb_mount,
"_load_tapdb_admin_app",
lambda **_kwargs: _dummy_tapdb_app(),
)
with _client() as client:
api_response = client.get("/api/v1/")
tapdb_response = client.get("/tapdb/", follow_redirects=False)
assert api_response.status_code == 200
assert tapdb_response.status_code != 404
def test_canonical_tapdb_dag_search_route_is_mounted(monkeypatch):
monkeypatch.delenv("BLOOM_DEV_AUTH_BYPASS", raising=False)
with _client() as client:
response = client.get("/api/dag/search", follow_redirects=False)
assert response.status_code == 401
assert response.json()["detail"].startswith("Authentication required")
def test_tapdb_dag_mount_uses_explicit_bloom_context(monkeypatch):
captured: dict[str, str] = {}
router = APIRouter()
@router.get("/api/dag/search")
async def _search():
return {"status": "ok"}
monkeypatch.setattr(
tapdb_dag,
"apply_runtime_environment",
lambda: SimpleNamespace(
target_label="target",
config_path="/tmp/bloom-tapdb-config.yaml",
),
)
monkeypatch.setattr(
tapdb_dag,
"create_tapdb_dag_router",
lambda **kwargs: (
captured.update({key: str(value) for key, value in kwargs.items()})
or router
),
)
app = FastAPI()
tapdb_dag.mount_tapdb_dag_api(app)
assert captured == {
"config_path": "/tmp/bloom-tapdb-config.yaml",
"service_name": "bloom",
}
assert "/api/dag/search" in {route.path for route in app.routes}
def test_app_shutdown_cleanup_runs(monkeypatch):
calls: list[str] = []
monkeypatch.setenv("BLOOM_TAPDB_MOUNT_ENABLED", "0")
monkeypatch.setattr("bloom_lims.app.stop_all_writers", lambda: calls.append("stop"))
with TestClient(create_app(), raise_server_exceptions=False):
pass
assert calls == ["stop"]
def test_mount_uses_explicit_tapdb_context(monkeypatch):
captured: dict[str, str] = {}
tapdb_app = FastAPI()
@tapdb_app.get("/")
async def _index():
return {"tapdb": "ok"}
monkeypatch.setattr(
tapdb_mount,
"apply_runtime_environment",
lambda: SimpleNamespace(
target_label="target",
config_path="/tmp/bloom-tapdb-config.yaml",
client_id="bloom",
database_name="bloom",
),
)
monkeypatch.setattr(
tapdb_mount,
"_load_tapdb_admin_app",
lambda **kwargs: (
captured.update({key: str(value) for key, value in kwargs.items()})
or tapdb_app
),
)
config = tapdb_mount.mount_tapdb_admin_subapp(FastAPI())
assert config is not None
assert captured == {
"config_path": "/tmp/bloom-tapdb-config.yaml",
"client_id": "bloom",
"database_name": "bloom",
}

Xet Storage Details

Size:
6.17 kB
·
Xet hash:
2f602c581956a6414ec95103b848b490523c6bde092d037bc9fe5223f54b5d41

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.