47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
創建測試數據
|
|
"""
|
|
|
|
from app import create_app, db
|
|
from app.models import Notification, NotificationType
|
|
from datetime import datetime
|
|
|
|
def create_test_notification():
|
|
"""創建測試通知"""
|
|
try:
|
|
app = create_app()
|
|
with app.app_context():
|
|
print("Creating test notification...")
|
|
|
|
# 創建測試通知
|
|
test_notification = Notification(
|
|
user_id=4, # ymirliu 用戶
|
|
type=NotificationType.INFO.value,
|
|
title='測試通知',
|
|
message='這是一個測試通知,用來驗證通知系統是否正常工作。',
|
|
extra_data={
|
|
'test_data': True,
|
|
'created_by': 'test_script'
|
|
}
|
|
)
|
|
|
|
db.session.add(test_notification)
|
|
db.session.commit()
|
|
|
|
print(f"Test notification created: {test_notification.notification_uuid}")
|
|
print(f"Total notifications in database: {Notification.query.count()}")
|
|
|
|
# 顯示所有通知
|
|
notifications = Notification.query.all()
|
|
for notification in notifications:
|
|
print(f" - {notification.title} ({notification.type})")
|
|
|
|
except Exception as e:
|
|
print(f"Error creating test notification: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == '__main__':
|
|
create_test_notification() |