优化数据
This commit is contained in:
72
test_search_state_fix.py
Normal file
72
test_search_state_fix.py
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
测试搜索状态保持功能
|
||||
"""
|
||||
import requests
|
||||
import json
|
||||
|
||||
def test_search_state_preservation():
|
||||
"""测试搜索状态保持功能"""
|
||||
print("🧪 开始测试搜索状态保持功能...")
|
||||
|
||||
# 测试URL
|
||||
base_url = "http://localhost:5000"
|
||||
|
||||
try:
|
||||
# 1. 访问主页
|
||||
print("📄 访问主页...")
|
||||
response = requests.get(base_url)
|
||||
if response.status_code == 200:
|
||||
print("✅ 主页访问成功")
|
||||
else:
|
||||
print(f"❌ 主页访问失败: {response.status_code}")
|
||||
return
|
||||
|
||||
# 2. 模拟搜索请求
|
||||
print("🔍 模拟搜索请求...")
|
||||
search_data = {
|
||||
'search_state': json.dumps({
|
||||
'searchTerm': '设计',
|
||||
'industry': 'all',
|
||||
'profession': 'all',
|
||||
'subCategory': 'all',
|
||||
'activeTab': 'all'
|
||||
}),
|
||||
'template_id': '1',
|
||||
'input_text': '测试输入文本',
|
||||
'csrf_token': 'test_token' # 实际使用时需要获取真实的CSRF token
|
||||
}
|
||||
|
||||
# 3. 模拟表单提交
|
||||
print("📝 模拟表单提交...")
|
||||
try:
|
||||
response = requests.post(base_url, data=search_data)
|
||||
if response.status_code == 200:
|
||||
print("✅ 表单提交成功")
|
||||
|
||||
# 检查响应中是否包含搜索状态
|
||||
if 'search_state' in response.text:
|
||||
print("✅ 搜索状态已保存")
|
||||
else:
|
||||
print("⚠️ 搜索状态可能未正确保存")
|
||||
|
||||
else:
|
||||
print(f"❌ 表单提交失败: {response.status_code}")
|
||||
except Exception as e:
|
||||
print(f"❌ 表单提交异常: {str(e)}")
|
||||
|
||||
print("\n🎯 测试完成!")
|
||||
print("💡 请在浏览器中手动测试以下流程:")
|
||||
print(" 1. 访问 http://localhost:5000")
|
||||
print(" 2. 在搜索框中输入关键词(如'设计')")
|
||||
print(" 3. 选择筛选条件")
|
||||
print(" 4. 输入一些文本内容")
|
||||
print(" 5. 点击'生成专业提示词'按钮")
|
||||
print(" 6. 检查页面刷新后是否保持了搜索状态")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 测试过程中出现错误: {str(e)}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_search_state_preservation()
|
||||
Reference in New Issue
Block a user