amazon-transcreation/seed/create_test_users.py
DJP 98fa16bfc3 feat: complete Phase 1-2 scaffold — backend, frontend, pipeline skeleton
Full-stack Amazon AI Transcreation Platform with:
- FastAPI backend (async, PostgreSQL, Redis, Celery) with 11 DB tables
- JWT auth (SSO-ready abstract provider pattern)
- 6-agent pipeline orchestrator with deterministic modules
- Next.js 14 frontend with Amazon branding (Ember fonts, orange/dark theme)
- Job wizard, monitoring HUD, output review, admin screens
- 154 TM/reference files imported, 12 locales configured
- Docker Compose for all services

Agents 2-5 (TM retrieval, ranker, transcreator, compliance) are stubs
pending Phase 3 LLM integration.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-10 12:31:43 -04:00

97 lines
2.9 KiB
Python

"""Seed script: Create test users (admin and tm_manager)."""
import asyncio
import sys
from pathlib import Path
# Add backend to path so we can import app modules
_seed_dir = Path(__file__).resolve().parent
_backend_dir = _seed_dir.parent / "backend"
if _backend_dir.is_dir():
sys.path.insert(0, str(_backend_dir))
else:
sys.path.insert(0, str(_seed_dir.parent))
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from app.auth.providers.jwt_provider import JWTAuthProvider
from app.config import settings
from app.models.client import Client
from app.models.user import User, UserClient, UserRole, UserStatus
TEST_USERS = [
{
"email": "admin@amazon.com",
"name": "Admin User",
"password": "admin123!",
"role": UserRole.admin,
},
{
"email": "manager@amazon.com",
"name": "TM Manager",
"password": "manager123!",
"role": UserRole.tm_manager,
},
{
"email": "reviewer@amazon.com",
"name": "Reviewer User",
"password": "reviewer123!",
"role": UserRole.reviewer,
},
]
async def seed_test_users() -> None:
"""Create test users if they don't exist."""
engine = create_async_engine(settings.DATABASE_URL, pool_pre_ping=True)
factory = async_sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False)
auth = JWTAuthProvider()
async with factory() as db:
# Get the Amazon client for association
client_result = await db.execute(select(Client).where(Client.name == "Amazon"))
amazon_client = client_result.scalar_one_or_none()
for user_data in TEST_USERS:
# Check if user exists
result = await db.execute(
select(User).where(User.email == user_data["email"])
)
existing = result.scalar_one_or_none()
if existing:
print(f"User '{user_data['email']}' already exists (id={existing.id})")
continue
user = User(
email=user_data["email"],
name=user_data["name"],
password_hash=auth.hash_password(user_data["password"]),
role=user_data["role"],
status=UserStatus.active,
)
db.add(user)
await db.flush()
# Associate with Amazon client
if amazon_client:
uc = UserClient(user_id=user.id, client_id=amazon_client.id)
db.add(uc)
print(
f"Created user '{user_data['email']}' "
f"(role={user_data['role'].value}, id={user.id})"
)
await db.commit()
await engine.dispose()
print("\nTest credentials:")
for u in TEST_USERS:
print(f" {u['email']} / {u['password']} ({u['role'].value})")
if __name__ == "__main__":
asyncio.run(seed_test_users())