Files
Aether/tests/unit/test_pool_oauth_expires.py
T

41 lines
1.2 KiB
Python
Raw Normal View History

from __future__ import annotations
from datetime import datetime, timezone
from types import SimpleNamespace
from src.api.admin.pool import routes as pool_routes
def test_derive_oauth_expires_at_from_auth_config_seconds(monkeypatch) -> None:
key = SimpleNamespace(auth_type="oauth", auth_config="enc", expires_at=None)
monkeypatch.setattr(
pool_routes.crypto_service,
"decrypt",
lambda _v: '{"expires_at": 1710000000}',
)
assert pool_routes._derive_oauth_expires_at(key) == 1710000000
def test_derive_oauth_expires_at_from_auth_config_milliseconds(monkeypatch) -> None:
key = SimpleNamespace(auth_type="oauth", auth_config="enc", expires_at=None)
monkeypatch.setattr(
pool_routes.crypto_service,
"decrypt",
lambda _v: '{"expires_at": 1710000000000}',
)
assert pool_routes._derive_oauth_expires_at(key) == 1710000000
def test_derive_oauth_expires_at_fallback_to_legacy_datetime() -> None:
key = SimpleNamespace(
auth_type="oauth",
auth_config=None,
expires_at=datetime(2026, 3, 4, 1, 2, 3, tzinfo=timezone.utc),
)
assert pool_routes._derive_oauth_expires_at(key) == 1772586123