37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
# tests/test_config.py
|
|
import pytest
|
|
|
|
from fastapi_oidc_op.config import Settings, StorageBackend
|
|
|
|
|
|
def test_default_settings() -> None:
|
|
settings = Settings(
|
|
issuer="http://localhost:8000",
|
|
)
|
|
assert settings.issuer == "http://localhost:8000"
|
|
assert settings.storage_backend == StorageBackend.SQLITE
|
|
assert settings.sqlite_path == "data/oidc_op.db"
|
|
assert settings.manage_client_id == "manage-app"
|
|
assert settings.invite_ttl == 86400
|
|
assert settings.theme == "default"
|
|
|
|
|
|
def test_mongodb_settings() -> None:
|
|
settings = Settings(
|
|
issuer="http://localhost:8000",
|
|
storage_backend=StorageBackend.MONGODB,
|
|
mongodb_uri="mongodb://mongo:27017",
|
|
mongodb_database="test_db",
|
|
)
|
|
assert settings.storage_backend == StorageBackend.MONGODB
|
|
assert settings.mongodb_uri == "mongodb://mongo:27017"
|
|
assert settings.mongodb_database == "test_db"
|
|
|
|
|
|
def test_settings_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
monkeypatch.setenv("OIDC_OP_ISSUER", "https://op.example.org")
|
|
monkeypatch.setenv("OIDC_OP_STORAGE_BACKEND", "mongodb")
|
|
monkeypatch.setenv("OIDC_OP_MONGODB_URI", "mongodb://remote:27017")
|
|
settings = Settings() # type: ignore[call-arg]
|
|
assert settings.issuer == "https://op.example.org"
|
|
assert settings.storage_backend == StorageBackend.MONGODB
|