import asyncio
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
from sqlalchemy.orm import sessionmaker
from sqlalchemy.future import select
from models import User
from config import DATABASE_URL
from auth import get_password_hash, pwd_context

engine = create_async_engine(DATABASE_URL, echo=False)
async_session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)

async def test_update():
    async with async_session() as db:
        stmt = select(User).where(User.username == "prueba")
        result = await db.execute(stmt)
        user = result.scalar_one_or_none()
        if user:
            print("Old hash:", user.hashed_password)
            user.hashed_password = get_password_hash("newpassword123")
            await db.commit()
            print("New hash:", user.hashed_password)
            
            # Verify it
            print("Verification:", pwd_context.verify("newpassword123", user.hashed_password))

if __name__ == "__main__":
    asyncio.run(test_update())
