feat: add takeover fields to Authorization model

Add takeover_enabled, takeover_mode, and takeover_delay_seconds columns
to the Authorization model with a SQLite migration, and include them
in to_dict(). Test: test_takeover_model.py.
This commit is contained in:
stefanfeng
2026-08-07 16:30:29 +08:00
parent 76f0730b57
commit 7327939b4d
4 changed files with 65 additions and 0 deletions
@@ -0,0 +1,26 @@
import pytest
from database import init_db, SessionLocal
from models import Authorization
@pytest.fixture(scope="session", autouse=True)
def setup_database():
"""Initialize DB tables and seed an Authorization row."""
init_db()
db = SessionLocal()
try:
existing = db.query(Authorization).first()
if existing is None:
auth = Authorization(
id="test-auth-1",
avatar_id="test-avatar-1",
target_type="user",
target_id="test-user-1",
target_name="Test User",
permissions=["read", "write"],
status="active",
)
db.add(auth)
db.commit()
finally:
db.close()
@@ -0,0 +1,30 @@
from database import SessionLocal
from models import Authorization
def test_authorization_takeover_fields():
db = SessionLocal()
try:
auth = db.query(Authorization).first()
assert auth is not None
# Check new fields exist and have default values
assert hasattr(auth, 'takeover_enabled')
assert hasattr(auth, 'takeover_mode')
assert hasattr(auth, 'takeover_delay_seconds')
assert auth.takeover_enabled == False
assert auth.takeover_mode == 'immediate'
assert auth.takeover_delay_seconds == 30
finally:
db.close()
def test_authorization_to_dict_includes_takeover():
db = SessionLocal()
try:
auth = db.query(Authorization).first()
d = auth.to_dict()
assert 'takeoverEnabled' in d
assert 'takeoverMode' in d
assert 'takeoverDelaySeconds' in d
finally:
db.close()