debug: 创建简单测试脚本和最终诊断指南

为了准确定位"下载按钮不显示"的问题,创建了:

1. test_simple.py - 简单测试脚本:
   - 自动获取配置并生成日报
   - 查看历史记录
   - 测试下载功能
   - 显示详细的请求和响应数据

2. 最终诊断指南.md:
   - 5个诊断步骤
   - 常见问题快速诊断
   - 需要提供的信息清单
   - 快速修复方案

使用步骤:
1. 运行 python test_simple.py
2. 查看完整输出
3. 检查服务器日志
4. 检查浏览器控制台
5. 提供所有信息以便准确定位问题

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
This commit is contained in:
user9994793890
2026-07-09 13:18:27 +08:00
parent 487a26e704
commit 3a06663f58
2 changed files with 372 additions and 0 deletions

181
test_simple.py Normal file
View File

@@ -0,0 +1,181 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
简单测试脚本:测试日报生成和下载
"""
import requests
import json
BASE_URL = "http://localhost:5000"
def test_generate():
"""测试生成日报"""
print("="*50)
print("测试1:生成日报")
print("="*50)
# 先获取配置列表
print("\n1. 获取配置列表...")
response = requests.get(f"{BASE_URL}/api/config")
print(f" 状态码: {response.status_code}")
if response.status_code != 200:
print(f" ❌ 获取配置失败: {response.text}")
return
configs = response.json().get('data', [])
print(f" ✓ 找到 {len(configs)} 个配置")
if not configs:
print(" ❌ 没有配置,请先创建配置")
return
# 使用第一个配置
config = configs[0]
config_id = config['id']
config_name = config['config_name']
print(f" 使用配置: {config_name} (ID: {config_id})")
# 生成日报
print("\n2. 生成日报...")
payload = {
'config_id': config_id,
'start_time': '2025-01-07 08:00:00',
'end_time': '2025-01-08 08:00:00'
}
print(f" 请求数据: {json.dumps(payload, ensure_ascii=False)}")
response = requests.post(f"{BASE_URL}/api/report/generate", json=payload)
print(f" 状态码: {response.status_code}")
print(f" 响应: {json.dumps(response.json(), ensure_ascii=False, indent=2)}")
if response.status_code != 200:
print(f" ❌ 生成失败")
return
result = response.json()
if not result.get('success'):
print(f" ❌ 生成失败: {result.get('message')}")
return
print(f" ✓ 生成成功")
print(f" 订单数: {result.get('total_orders')}")
print(f" 总金额: {result.get('total_amount')}")
print(f" 文件路径: {result.get('file_path')}")
return result
def test_history():
"""测试历史记录"""
print("\n" + "="*50)
print("测试2:查看历史记录")
print("="*50)
response = requests.get(f"{BASE_URL}/api/report/history")
print(f"状态码: {response.status_code}")
if response.status_code != 200:
print(f"❌ 获取历史记录失败: {response.text}")
return
result = response.json()
if not result.get('success'):
print(f"❌ 获取失败: {result.get('message')}")
return
history = result.get('data', [])
print(f"✓ 找到 {len(history)} 条记录")
if not history:
print("❌ 没有历史记录")
return
print("\n最近的记录:")
for item in history[:3]:
print(f" ID: {item['id']}")
print(f" 状态: {'成功' if item.get('status') == 1 else '失败'}")
print(f" file_path: {item.get('file_path', '空')}")
print(f" 日期: {item.get('report_date')}")
print(f" 名称: {item.get('split_name')}")
print()
# 检查是否有可下载的文件
has_file = any(item.get('file_path') for item in history)
if has_file:
print("✓ 有可下载的文件")
else:
print("❌ 没有可下载的文件(所有记录的file_path都为空)")
def test_download():
"""测试下载"""
print("\n" + "="*50)
print("测试3:测试下载")
print("="*50)
# 获取历史记录
response = requests.get(f"{BASE_URL}/api/report/history")
if response.status_code != 200:
print("❌ 获取历史记录失败")
return
history = response.json().get('data', [])
if not history:
print("❌ 没有历史记录")
return
# 找到有文件的记录
file_record = None
for item in history:
if item.get('file_path'):
file_record = item
break
if not file_record:
print("❌ 没有找到有文件的记录")
return
file_path = file_record['file_path']
print(f"找到文件: {file_path}")
# 测试下载
print(f"\n测试下载: {file_path}")
response = requests.get(f"{BASE_URL}/api/download", params={'path': file_path})
print(f"状态码: {response.status_code}")
if response.status_code == 200:
print(f"✓ 下载成功")
print(f"文件大小: {len(response.content)} 字节")
else:
print(f"❌ 下载失败: {response.text}")
def main():
print("\n" + "="*50)
print("日报系统测试工具")
print("="*50)
try:
# 测试生成
result = test_generate()
# 测试历史
test_history()
# 测试下载
test_download()
print("\n" + "="*50)
print("测试完成")
print("="*50)
except requests.exceptions.ConnectionError:
print("\n❌ 无法连接到服务器")
print("请确保服务正在运行: python app.py")
except Exception as e:
print(f"\n❌ 测试出错: {e}")
print("\n按回车键退出...")
input()
if __name__ == '__main__':
main()