27 lines
886 B
Python
27 lines
886 B
Python
from sqlalchemy import create_engine, select
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.config import get_settings
|
|
from app.db.models import User
|
|
from app.services.auth_service import verify_password
|
|
|
|
|
|
def test_initialize_fresh_database_creates_default_admin(monkeypatch, tmp_path):
|
|
database = tmp_path / "platform.db"
|
|
monkeypatch.setenv("DATABASE_URL", f"sqlite:///{database}")
|
|
get_settings.cache_clear()
|
|
try:
|
|
from app.init_db import initialize
|
|
|
|
initialize()
|
|
initialize()
|
|
|
|
with Session(create_engine(f"sqlite:///{database}")) as db:
|
|
users = list(db.scalars(select(User)))
|
|
assert len(users) == 1
|
|
assert users[0].username == "gly"
|
|
assert users[0].is_admin is True
|
|
assert verify_password("maxta2026", users[0].password_hash)
|
|
finally:
|
|
get_settings.cache_clear()
|