添加注册登录功能
This commit is contained in:
75
test_favorite_function.py
Normal file
75
test_favorite_function.py
Normal file
@@ -0,0 +1,75 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试收藏功能
|
||||
"""
|
||||
from src.flask_prompt_master import create_app, db
|
||||
from src.flask_prompt_master.models.favorites import Favorite
|
||||
|
||||
def test_favorite_function():
|
||||
"""测试收藏功能"""
|
||||
app = create_app()
|
||||
|
||||
with app.app_context():
|
||||
print("=" * 50)
|
||||
print("收藏功能测试")
|
||||
print("=" * 50)
|
||||
|
||||
try:
|
||||
# 检查收藏表
|
||||
total_favorites = Favorite.query.count()
|
||||
print(f"📊 总收藏数: {total_favorites}")
|
||||
|
||||
if total_favorites > 0:
|
||||
# 显示最近的收藏
|
||||
recent_favorites = Favorite.query.order_by(Favorite.created_time.desc()).limit(3).all()
|
||||
print(f"\n📝 最近3个收藏:")
|
||||
for i, fav in enumerate(recent_favorites, 1):
|
||||
print(f" {i}. ID: {fav.id}")
|
||||
print(f" 用户: {fav.user_id}")
|
||||
print(f" 原始文本: {fav.original_text[:50]}...")
|
||||
print(f" 分类: {fav.category}")
|
||||
print(f" 时间: {fav.created_time}")
|
||||
print()
|
||||
|
||||
# 测试添加新收藏
|
||||
print("💾 测试添加新收藏...")
|
||||
new_favorite = Favorite(
|
||||
user_id='192.168.31.136',
|
||||
template_id=1,
|
||||
original_text='测试收藏功能修复',
|
||||
generated_prompt='这是一个测试收藏,用于验证修复后的功能',
|
||||
category='通用工具',
|
||||
notes='功能测试'
|
||||
)
|
||||
|
||||
db.session.add(new_favorite)
|
||||
db.session.commit()
|
||||
|
||||
print(f"✅ 新收藏添加成功!ID: {new_favorite.id}")
|
||||
|
||||
# 验证新收藏
|
||||
saved_favorite = Favorite.query.get(new_favorite.id)
|
||||
if saved_favorite:
|
||||
print(f"✅ 收藏验证成功:")
|
||||
print(f" 原始文本: {saved_favorite.original_text}")
|
||||
print(f" 生成提示词: {saved_favorite.generated_prompt[:50]}...")
|
||||
print(f" 分类: {saved_favorite.category}")
|
||||
else:
|
||||
print("❌ 收藏验证失败")
|
||||
|
||||
# 清理测试数据
|
||||
db.session.delete(new_favorite)
|
||||
db.session.commit()
|
||||
print("🧹 测试数据已清理")
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("✅ 收藏功能测试完成!")
|
||||
print("=" * 50)
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 测试过程中出现错误: {str(e)}")
|
||||
db.session.rollback()
|
||||
raise
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_favorite_function()
|
||||
Reference in New Issue
Block a user