84 lines
2.5 KiB
Python
Executable File
84 lines
2.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
快速测试脚本 - 验证服务是否正常运行
|
|
"""
|
|
import requests
|
|
import time
|
|
import sys
|
|
|
|
def test_server():
|
|
"""测试服务器是否正常运行"""
|
|
base_url = "http://localhost:8000"
|
|
|
|
print("🧪 文件传输服务测试")
|
|
print("=" * 50)
|
|
|
|
# 测试首页
|
|
print("1. 测试首页...")
|
|
try:
|
|
response = requests.get(base_url, timeout=10)
|
|
if response.status_code == 200:
|
|
print("✅ 首页正常 (200)")
|
|
if "文件传输服务" in response.text:
|
|
print("✅ 页面内容正确")
|
|
else:
|
|
print("⚠️ 页面内容异常")
|
|
else:
|
|
print(f"❌ 首页异常 ({response.status_code})")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 无法连接到服务器: {e}")
|
|
print("💡 请确保服务器已启动: python app.py")
|
|
return False
|
|
|
|
# 测试静态文件
|
|
print("\n2. 测试静态文件...")
|
|
static_files = [
|
|
"/static/style.css",
|
|
"/static/app.js"
|
|
]
|
|
|
|
for file_path in static_files:
|
|
try:
|
|
response = requests.get(f"{base_url}{file_path}", timeout=5)
|
|
if response.status_code == 200:
|
|
print(f"✅ {file_path} - 正常")
|
|
else:
|
|
print(f"❌ {file_path} - 异常 ({response.status_code})")
|
|
except Exception as e:
|
|
print(f"❌ {file_path} - 错误: {e}")
|
|
|
|
# 测试API信息
|
|
print("\n3. 测试API...")
|
|
try:
|
|
response = requests.get(f"{base_url}/api", timeout=5)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print("✅ API信息正常")
|
|
print(f" 服务: {data.get('service', 'N/A')}")
|
|
print(f" 版本: {data.get('version', 'N/A')}")
|
|
else:
|
|
print(f"❌ API异常 ({response.status_code})")
|
|
except Exception as e:
|
|
print(f"❌ API错误: {e}")
|
|
|
|
# 测试API文档
|
|
print("\n4. 测试API文档...")
|
|
try:
|
|
response = requests.get(f"{base_url}/docs", timeout=5)
|
|
if response.status_code == 200:
|
|
print("✅ API文档正常")
|
|
else:
|
|
print(f"❌ API文档异常 ({response.status_code})")
|
|
except Exception as e:
|
|
print(f"❌ API文档错误: {e}")
|
|
|
|
print("\n" + "=" * 50)
|
|
print("🎉 测试完成!")
|
|
print(f"🌐 访问地址: {base_url}")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
if not test_server():
|
|
sys.exit(1) |