tenant-engine/tests/test_backend_selection.py

34 lines
1,007 B
Python
Raw Normal View History

from dataclasses import replace
import pytest
from tenant_engine.config import Settings
from tenant_engine.main import _build_store
from tenant_engine.sqlite_store import SQLiteTenantStore
def _settings() -> Settings:
return Settings(
flex_auth_base_url=None,
flex_auth_timeout_seconds=1,
host="127.0.0.1",
port=8090,
)
def test_store_selection_defaults_to_memory_and_selects_sqlite(tmp_path) -> None:
assert _build_store(_settings()) is None
store = _build_store(replace(_settings(), database_path=str(tmp_path / "tenant.db")))
assert isinstance(store, SQLiteTenantStore)
def test_store_selection_refuses_ambiguous_configuration(tmp_path) -> None:
with pytest.raises(RuntimeError, match="ambiguous store configuration"):
_build_store(
replace(
_settings(),
database_path=str(tmp_path / "tenant.db"),
database_url_file=str(tmp_path / "database-url"),
)
)