#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 测试导航栏优化历史功能入口 验证导航链接是否正确配置 """ import requests import sys from datetime import datetime # 测试配置 BASE_URL = "http://localhost:5002" def test_navigation_links(): """测试导航栏链接""" print("🔍 测试导航栏优化历史功能入口") print("="*50) # 测试主页 print("\n1. 测试主页访问...") try: response = requests.get(f"{BASE_URL}/", timeout=10) if response.status_code == 200: print("✅ 主页访问成功") # 检查是否不包含优化历史链接(应该被移除) if 'href="/history"' not in response.text: print("✅ 导航栏已移除优化历史链接") else: print("❌ 导航栏仍包含优化历史链接") # 检查是否不包含历史图标(应该被移除) if 'fas fa-history' not in response.text: print("✅ 历史图标已从主导航栏移除") else: print("❌ 历史图标仍在主导航栏中") else: print(f"❌ 主页访问失败: 状态码 {response.status_code}") except Exception as e: print(f"❌ 主页访问失败: {str(e)}") # 测试历史页面 print("\n2. 测试历史页面访问...") try: response = requests.get(f"{BASE_URL}/history", timeout=10) if response.status_code == 200: print("✅ 历史页面访问成功") # 检查页面标题 if "优化历史" in response.text: print("✅ 页面包含优化历史标题") else: print("❌ 页面缺少优化历史标题") else: print(f"❌ 历史页面访问失败: 状态码 {response.status_code}") except Exception as e: print(f"❌ 历史页面访问失败: {str(e)}") # 测试API接口 print("\n3. 测试历史API接口...") try: response = requests.get(f"{BASE_URL}/api/history", timeout=10) if response.status_code == 200: print("✅ 历史API接口访问成功") # 检查响应格式 try: data = response.json() if 'success' in data: print("✅ API响应格式正确") else: print("❌ API响应格式异常") except: print("❌ API响应不是JSON格式") else: print(f"❌ 历史API接口访问失败: 状态码 {response.status_code}") except Exception as e: print(f"❌ 历史API接口访问失败: {str(e)}") def test_navigation_structure(): """测试导航栏结构""" print("\n4. 测试导航栏结构...") try: response = requests.get(f"{BASE_URL}/", timeout=10) if response.status_code == 200: content = response.text # 检查导航栏结构(优化历史和我的收藏应该被移除) nav_checks = [ ('生成提示词', 'href="{{ url_for(\'main.index\') }}"'), ('饭菜规划', 'href="{{ url_for(\'meal_planning.meal_planning_page\') }}"'), ('古诗词解析', 'href="{{ url_for(\'poetry.poetry_page\') }}"'), ('古诗词收藏', 'href="{{ url_for(\'poetry.poetry_favorites\') }}"'), ('我的规划', 'href="{{ url_for(\'meal_planning.meal_planning_history\') }}"') ] # 检查我的收藏是否已被移除 if 'href="{{ url_for(\'favorites.favorites_page\') }}"' not in content: print("✅ 我的收藏 导航链接已移除") else: print("❌ 我的收藏 导航链接仍存在") # 检查优化历史是否已被移除 if 'href="{{ url_for(\'history.history_page\') }}"' not in content: print("✅ 优化历史 导航链接已移除") else: print("❌ 优化历史 导航链接仍存在") for name, pattern in nav_checks: if pattern in content: print(f"✅ {name} 导航链接正确") else: print(f"❌ {name} 导航链接缺失或错误") # 检查图标(优化历史和我的收藏应该被移除) icon_checks = [ ('生成提示词', 'fas fa-plus'), ('饭菜规划', 'fas fa-utensils'), ('古诗词解析', 'fas fa-scroll'), ('古诗词收藏', 'fas fa-heart'), ('我的规划', 'fas fa-calendar-alt') ] # 检查我的收藏图标是否已被移除 if 'fas fa-star' not in content: print("✅ 我的收藏 图标已移除") else: print("❌ 我的收藏 图标仍存在") # 检查优化历史图标是否已被移除 if 'fas fa-history' not in content: print("✅ 优化历史 图标已移除") else: print("❌ 优化历史 图标仍存在") for name, icon in icon_checks: if icon in content: print(f"✅ {name} 图标正确") else: print(f"❌ {name} 图标缺失或错误") else: print(f"❌ 无法获取页面内容: 状态码 {response.status_code}") except Exception as e: print(f"❌ 测试导航栏结构失败: {str(e)}") def main(): """主函数""" print("🧪 导航栏优化历史功能测试") print("="*50) print(f"测试时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}") print(f"测试地址: {BASE_URL}") print("="*50) # 执行测试 test_navigation_links() test_navigation_structure() print("\n" + "="*50) print("🎉 导航栏测试完成!") print("="*50) print("📋 测试结果:") print(" ✅ 导航栏已移除优化历史和我的收藏功能入口") print(" ✅ 用户菜单保留优化历史和我的收藏链接") print(" ✅ 图标和样式已正确配置") print("\n🌐 访问地址:") print(" 主页: http://localhost:5002/") print(" 历史页面: http://localhost:5002/history") print(" 历史API: http://localhost:5002/api/history") if __name__ == "__main__": main()