#!/usr/bin/env python3
"""
完整功能测试脚本
测试登录后的各项功能
"""
import asyncio
import httpx
from loguru import logger
async def test_all_features():
"""测试所有功能"""
base_url = "http://localhost:18060"
print("="*60)
print("小红书功能测试")
print("="*60)
async with httpx.AsyncClient(timeout=30.0) as client:
# 1. 健康检查
print("\n1. 健康检查...")
try:
response = await client.get(f"{base_url}/health")
print(f" 状态: {response.status_code}")
print(f" 响应: {response.json()}")
except Exception as e:
print(f" ✗ 失败: {e}")
# 2. 登录状态
print("\n2. 检查登录状态...")
try:
response = await client.get(f"{base_url}/api/v1/login/status")
data = response.json()
print(f" 状态: {response.status_code}")
print(f" 登录状态: {data.get('logged_in', False)}")
if not data.get('logged_in', False):
print(" ⚠️ 显示未登录,但 cookies 已加载")
print(" 这可能是因为登录检查逻辑需要调整")
except Exception as e:
print(f" ✗ 失败: {e}")
# 3. 尝试获取 Feed 列表
print("\n3. 尝试获取 Feed 列表...")
try:
response = await client.get(f"{base_url}/api/v1/feeds/list")
print(f" 状态: {response.status_code}")
if response.status_code == 200:
data = response.json()
feeds = data.get('feeds', [])
print(f" ✓ 成功获取 {len(feeds)} 条 Feed")
if feeds:
print("\n 前 3 条 Feed:")
for i, feed in enumerate(feeds[:3], 1):
title = feed.get('note_card', {}).get('display_title', 'N/A')
print(f" {i}. {title[:50]}...")
else:
print(f" 响应: {response.text[:200]}")
except Exception as e:
print(f" ✗ 失败: {e}")
# 4. 尝试搜索
print("\n4. 尝试搜索...")
try:
response = await client.post(
f"{base_url}/api/v1/feeds/search",
json={"keyword": "美食"}
)
print(f" 状态: {response.status_code}")
if response.status_code == 200:
data = response.json()
feeds = data.get('feeds', [])
print(f" ✓ 搜索到 {len(feeds)} 条结果")
if feeds:
print("\n 前 3 条搜索结果:")
for i, feed in enumerate(feeds[:3], 1):
title = feed.get('note_card', {}).get('display_title', 'N/A')
print(f" {i}. {title[:50]}...")
else:
print(f" 响应: {response.text[:200]}")
except Exception as e:
print(f" ✗ 失败: {e}")
print("\n" + "="*60)
print("测试完成")
print("="*60)
if __name__ == "__main__":
try:
asyncio.run(test_all_features())
except Exception as e:
print(f"\n测试失败: {e}")
import traceback
traceback.print_exc()