- 从服务器拉取完整代码 - 按框架规范整理项目结构 - 配置 Drone CI 测试环境部署 - 包含后端(FastAPI)、前端(Vue3)、管理端 技术栈: Vue3 + TypeScript + FastAPI + MySQL
125 lines
3.8 KiB
Python
125 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
前端登录测试脚本
|
|
"""
|
|
import requests
|
|
import json
|
|
import time
|
|
|
|
def test_login_flow():
|
|
"""测试完整的登录流程"""
|
|
print("🔍 开始前端登录测试...")
|
|
|
|
# 1. 测试前端页面访问
|
|
try:
|
|
response = requests.get("http://localhost:3001/login")
|
|
if response.status_code == 200:
|
|
print("✅ 前端登录页面可访问")
|
|
else:
|
|
print(f"❌ 前端登录页面访问失败: {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 前端页面访问失败: {e}")
|
|
return False
|
|
|
|
# 2. 测试后端登录API
|
|
try:
|
|
login_data = {"username": "testuser", "password": "123456"}
|
|
response = requests.post("http://localhost:8000/api/v1/auth/login", json=login_data)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print("✅ 后端登录API成功")
|
|
print(f" 用户: {data['data']['user']['username']}")
|
|
print(f" 角色: {data['data']['user']['role']}")
|
|
|
|
# 保存token用于后续测试
|
|
global access_token, refresh_token
|
|
access_token = data['data']['token']['access_token']
|
|
refresh_token = data['data']['token']['refresh_token']
|
|
return True
|
|
else:
|
|
print(f"❌ 后端登录API失败: {response.status_code}")
|
|
print(f" 响应: {response.text}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 后端API调用失败: {e}")
|
|
return False
|
|
|
|
def test_token_refresh():
|
|
"""测试token刷新"""
|
|
global access_token, refresh_token
|
|
|
|
if not access_token or not refresh_token:
|
|
print("❌ 没有可用的token进行刷新测试")
|
|
return False
|
|
|
|
print("\n🔄 测试token刷新...")
|
|
|
|
try:
|
|
refresh_data = {"refresh_token": refresh_token}
|
|
response = requests.post("http://localhost:8000/api/v1/auth/refresh", json=refresh_data)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print("✅ Token刷新成功")
|
|
return True
|
|
else:
|
|
print(f"❌ Token刷新失败: {response.status_code}")
|
|
print(f" 响应: {response.text}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Token刷新请求失败: {e}")
|
|
return False
|
|
|
|
def test_frontend_proxy():
|
|
"""测试前端代理配置"""
|
|
print("\n🌐 测试前端代理...")
|
|
|
|
try:
|
|
# 通过前端代理调用后端API
|
|
headers = {"Content-Type": "application/json"}
|
|
response = requests.post("http://localhost:3001/api/v1/auth/login",
|
|
json={"username": "testuser", "password": "123456"},
|
|
headers=headers)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
print("✅ 前端代理API调用成功")
|
|
print(f" 响应格式正确: {type(data)}")
|
|
return True
|
|
else:
|
|
print(f"❌ 前端代理API调用失败: {response.status_code}")
|
|
print(f" 响应: {response.text}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 前端代理API调用失败: {e}")
|
|
return False
|
|
|
|
def main():
|
|
"""主测试函数"""
|
|
print("🚀 前端登录完整测试")
|
|
print("=" * 50)
|
|
|
|
# 测试后端API
|
|
if not test_login_flow():
|
|
print("❌ 后端登录测试失败")
|
|
return False
|
|
|
|
# 测试token刷新
|
|
if not test_token_refresh():
|
|
print("❌ Token刷新测试失败")
|
|
return False
|
|
|
|
# 测试前端代理
|
|
if not test_frontend_proxy():
|
|
print("❌ 前端代理测试失败")
|
|
return False
|
|
|
|
print("\n" + "=" * 50)
|
|
print("🎉 所有测试通过!前端登录功能正常!")
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
main()
|