Upload create_test_user.py with huggingface_hub
Browse files- create_test_user.py +55 -0
create_test_user.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""テストユーザーを作成"""
|
| 3 |
+
import sys
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# プロジェクトルートをパスに追加
|
| 7 |
+
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
|
| 8 |
+
|
| 9 |
+
from sqlalchemy.orm import Session
|
| 10 |
+
from backend.app.database.session import SessionLocal
|
| 11 |
+
from backend.app.database.models import User
|
| 12 |
+
from backend.app.utils.password_hash import get_password_hash
|
| 13 |
+
|
| 14 |
+
def create_test_user():
|
| 15 |
+
"""テストユーザーを作成"""
|
| 16 |
+
db = SessionLocal()
|
| 17 |
+
|
| 18 |
+
try:
|
| 19 |
+
# 既存ユーザーを確認
|
| 20 |
+
existing_user = db.query(User).filter(User.email == "test@example.com").first()
|
| 21 |
+
if existing_user:
|
| 22 |
+
print("✅ テストユーザーは既に存在します")
|
| 23 |
+
print(f" Email: test@example.com")
|
| 24 |
+
print(f" Password: test123")
|
| 25 |
+
print(f" Role: {existing_user.role}")
|
| 26 |
+
return
|
| 27 |
+
|
| 28 |
+
# テストユーザーを作成
|
| 29 |
+
test_user = User(
|
| 30 |
+
email="test@example.com",
|
| 31 |
+
username="testuser",
|
| 32 |
+
hashed_password=get_password_hash("test123"),
|
| 33 |
+
role="editor", # editorロールで作成
|
| 34 |
+
is_active=True
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
db.add(test_user)
|
| 38 |
+
db.commit()
|
| 39 |
+
db.refresh(test_user)
|
| 40 |
+
|
| 41 |
+
print("✅ テストユーザーを作成しました!")
|
| 42 |
+
print(f" Email: test@example.com")
|
| 43 |
+
print(f" Password: test123")
|
| 44 |
+
print(f" Role: editor")
|
| 45 |
+
print()
|
| 46 |
+
print("フロントエンド (http://localhost:5173) でログインできます")
|
| 47 |
+
|
| 48 |
+
except Exception as e:
|
| 49 |
+
print(f"❌ エラー: {e}")
|
| 50 |
+
db.rollback()
|
| 51 |
+
finally:
|
| 52 |
+
db.close()
|
| 53 |
+
|
| 54 |
+
if __name__ == "__main__":
|
| 55 |
+
create_test_user()
|