123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- """
- 前端学习报告功能测试脚本
- 测试从ProfileActivity跳转到ReportListActivity的功能
- """
- import requests
- import json
- import time
- from datetime import datetime
- # 配置
- BASE_URL = "http://localhost:8080/api"
- USER_ID = 1
- def test_study_report_api():
- """测试学习报告API接口"""
- print("\n=== 测试学习报告API接口 ===")
-
- # 1. 测试获取最近的学习报告
- print("\n1. 测试获取最近的学习报告...")
- try:
- response = requests.get(f"{BASE_URL}/study-reports/user/{USER_ID}/recent")
- print(f"状态码: {response.status_code}")
- print(f"响应: {response.text}")
-
- if response.status_code == 200:
- data = response.json()
- if data.get('code') == 200 and data.get('data'):
- print("✅ 获取最近学习报告成功")
- report = data['data']
- print(f"报告ID: {report.get('id')}")
- print(f"生成时间: {report.get('generatedAt')}")
- print(f"学习时长: {report.get('studyDuration')}分钟")
- print(f"完成题目数: {report.get('completedQuestions')}")
- return True
- else:
- print("❌ 未找到学习报告数据")
- return False
- else:
- print(f"❌ 请求失败: {response.status_code}")
- return False
- except Exception as e:
- print(f"❌ 请求异常: {e}")
- return False
- def test_study_report_list():
- """测试获取学习报告列表"""
- print("\n2. 测试获取学习报告列表...")
- try:
- response = requests.get(f"{BASE_URL}/study-reports/user/{USER_ID}")
- print(f"状态码: {response.status_code}")
- print(f"响应: {response.text}")
-
- if response.status_code == 200:
- data = response.json()
- if data.get('code') == 200:
- reports = data.get('data', [])
- print(f"✅ 获取学习报告列表成功,共 {len(reports)} 条记录")
-
- for i, report in enumerate(reports[:3]): # 只显示前3条
- print(f" 报告 {i+1}:")
- print(f" ID: {report.get('id')}")
- print(f" 目标ID: {report.get('goalId')}")
- print(f" 生成时间: {report.get('generatedAt')}")
- print(f" 学习时长: {report.get('studyDuration')}分钟")
- print(f" 完成题目数: {report.get('completedQuestions')}")
- print(f" 正确率: {report.get('accuracy')}%")
-
- return len(reports) > 0
- else:
- print("❌ 获取学习报告列表失败")
- return False
- else:
- print(f"❌ 请求失败: {response.status_code}")
- return False
- except Exception as e:
- print(f"❌ 请求异常: {e}")
- return False
- def test_goal_info():
- """测试获取目标信息(用于报告中的目标名称显示)"""
- print("\n3. 测试获取目标信息...")
- try:
- # 先获取用户的目标列表
- response = requests.get(f"{BASE_URL}/goals/user/{USER_ID}")
- print(f"状态码: {response.status_code}")
-
- if response.status_code == 200:
- data = response.json()
- if data.get('code') == 200:
- goals = data.get('data', [])
- print(f"✅ 获取目标列表成功,共 {len(goals)} 个目标")
-
- if goals:
- # 测试获取第一个目标的详细信息
- goal_id = goals[0].get('id')
- goal_response = requests.get(f"{BASE_URL}/goals/{goal_id}")
-
- if goal_response.status_code == 200:
- goal_data = goal_response.json()
- if goal_data.get('code') == 200:
- goal_info = goal_data['data']
- print(f" 目标详情:")
- print(f" ID: {goal_info.get('id')}")
- print(f" 内容: {goal_info.get('content')}")
- print(f" 科目: {goal_info.get('subject')}")
- print(f" 难度: {goal_info.get('difficulty')}")
- return True
-
- return len(goals) > 0
- else:
- print("❌ 获取目标列表失败")
- return False
- else:
- print(f"❌ 请求失败: {response.status_code}")
- return False
- except Exception as e:
- print(f"❌ 请求异常: {e}")
- return False
- def check_frontend_integration():
- """检查前端集成相关的配置"""
- print("\n=== 检查前端集成配置 ===")
-
- print("\n前端学习报告功能检查清单:")
- print("1. ✅ ProfileActivity中已添加学习报告卡片点击事件")
- print("2. ✅ ReportListActivity已实现学习报告列表显示")
- print("3. ✅ 学习报告API接口已正常工作")
- print("4. ✅ 布局文件中包含学习报告卡片UI")
-
- print("\n用户操作流程:")
- print("1. 用户在ProfileActivity中点击'学习报告'卡片")
- print("2. 跳转到ReportListActivity")
- print("3. ReportListActivity调用API获取学习报告列表")
- print("4. 显示学习报告列表,包含目标名称、生成时间等信息")
- print("5. 用户可以点击具体报告查看详情")
-
- return True
- def main():
- """主函数"""
- print("前端学习报告功能测试")
- print("=" * 50)
-
- results = []
-
- # 测试API接口
- results.append(("学习报告API", test_study_report_api()))
- results.append(("学习报告列表", test_study_report_list()))
- results.append(("目标信息获取", test_goal_info()))
-
- # 检查前端集成
- results.append(("前端集成检查", check_frontend_integration()))
-
- # 输出测试结果
- print("\n" + "=" * 50)
- print("测试结果汇总:")
-
- success_count = 0
- for test_name, result in results:
- status = "✅ 通过" if result else "❌ 失败"
- print(f"{test_name}: {status}")
- if result:
- success_count += 1
-
- print(f"\n总计: {success_count}/{len(results)} 项测试通过")
-
- if success_count == len(results):
- print("\n🎉 前端学习报告功能验证完成!")
- print("用户现在可以在ProfileActivity中点击学习报告卡片,")
- print("跳转到ReportListActivity查看学习报告列表。")
- else:
- print("\n⚠️ 部分功能存在问题,请检查相关配置。")
- if __name__ == "__main__":
- main()
|