video-accessibility/backend/create_test_users.py
2025-08-24 16:28:33 -05:00

78 lines
No EOL
2.6 KiB
Python

#!/usr/bin/env python3
"""Create test users for the accessible video platform."""
import asyncio
from datetime import datetime
from passlib.context import CryptContext
from motor.motor_asyncio import AsyncIOMotorClient
from app.core.config import settings
from app.models.user import UserRole
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
async def create_test_users():
"""Create test users in the database."""
print("Connecting to MongoDB...")
client = AsyncIOMotorClient(settings.mongodb_uri)
db = client[settings.mongodb_db]
# Test connection
await client.admin.command('ping')
print("Connected to MongoDB successfully")
users_collection = db.users
# Check if users already exist
existing_admin = await users_collection.find_one({"email": "admin@example.com"})
existing_reviewer = await users_collection.find_one({"email": "reviewer@example.com"})
test_users = [
{
"email": "admin@example.com",
"hashed_password": pwd_context.hash("admin"),
"full_name": "Admin User",
"role": UserRole.ADMIN.value,
"is_active": True,
"created_at": datetime.utcnow(),
"updated_at": datetime.utcnow(),
},
{
"email": "reviewer@example.com",
"hashed_password": pwd_context.hash("reviewer"),
"full_name": "Reviewer User",
"role": UserRole.REVIEWER.value,
"is_active": True,
"created_at": datetime.utcnow(),
"updated_at": datetime.utcnow(),
},
{
"email": "client@example.com",
"hashed_password": pwd_context.hash("client123"),
"full_name": "Client User",
"role": UserRole.CLIENT.value,
"is_active": True,
"created_at": datetime.utcnow(),
"updated_at": datetime.utcnow(),
}
]
for user in test_users:
existing = await users_collection.find_one({"email": user["email"]})
if existing:
print(f"User {user['email']} already exists, skipping...")
continue
result = await users_collection.insert_one(user)
print(f"Created user: {user['email']} (ID: {result.inserted_id})")
# Show all users
print("\nAll users in database:")
async for user in users_collection.find({}, {"email": 1, "role": 1, "is_active": 1}):
print(f" {user['email']} - {user['role']} - Active: {user['is_active']}")
client.close()
print("Done!")
if __name__ == "__main__":
asyncio.run(create_test_users())