Fix test test_create_first_user()
This commit is contained in:
@@ -15,7 +15,7 @@ scanner = BackgroundScanner(db=get_db_session())
|
||||
async def lifespan(app: FastAPI):
|
||||
load_dotenv()
|
||||
create_db_and_tables()
|
||||
create_first_user()
|
||||
create_first_user(db=get_db_session())
|
||||
print("Database created and tables initialized.")
|
||||
scanner.start()
|
||||
yield
|
||||
|
||||
@@ -83,20 +83,19 @@ def auth_is_admin(
|
||||
)
|
||||
return True
|
||||
|
||||
def create_first_user():
|
||||
def create_first_user(db: Session):
|
||||
print("Checking for admin user")
|
||||
with Session(engine) as db:
|
||||
admin_user = db.exec(select(UserDB)).first()
|
||||
if admin_user is None:
|
||||
password = ''.join(secrets.choice(string.digits) for i in range(8))
|
||||
print("Creating first admin user with password", password)
|
||||
user = UserDB(
|
||||
name="admin",
|
||||
passwordhash=get_password_hash(password),
|
||||
is_admin=True
|
||||
)
|
||||
return add_and_refresh(db, user)
|
||||
print(f"Admin user already exists: {admin_user.name}")
|
||||
admin_user = db.exec(select(UserDB)).first()
|
||||
if admin_user is None:
|
||||
password = ''.join(secrets.choice(string.digits) for i in range(8))
|
||||
print("Creating first admin user with password", password)
|
||||
user = UserDB(
|
||||
name="admin",
|
||||
passwordhash=get_password_hash(password),
|
||||
is_admin=True
|
||||
)
|
||||
return add_and_refresh(db, user)
|
||||
print(f"Admin user already exists: {admin_user.name}")
|
||||
|
||||
|
||||
@token_router.post("/token")
|
||||
|
||||
Reference in New Issue
Block a user