forked from xiaohei/taiji-AI-PAD
101 lines
2.7 KiB
Python
101 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试所有管理员账户登录
|
|
"""
|
|
import requests
|
|
import json
|
|
|
|
BASE_URL = "http://localhost:8002"
|
|
|
|
# 管理员账户列表
|
|
ADMINS = [
|
|
{
|
|
"role": "super_admin",
|
|
"email": "superadmin@taiji-ai.com",
|
|
"password": "Admin@123456",
|
|
"login_role": "super_admin"
|
|
},
|
|
{
|
|
"role": "billing_admin",
|
|
"email": "newbilling@test.com",
|
|
"password": "Billing@123456",
|
|
"login_role": "billing_admin"
|
|
},
|
|
{
|
|
"role": "operations_admin",
|
|
"email": "newops@test.com",
|
|
"password": "Ops@123456",
|
|
"login_role": "operations_admin"
|
|
},
|
|
{
|
|
"role": "channel_admin",
|
|
"email": "channel-a@test.com",
|
|
"password": "ChannelA@123456",
|
|
"login_role": "channel"
|
|
}
|
|
]
|
|
|
|
def test_admin_login(admin_info):
|
|
"""测试管理员登录"""
|
|
print(f"\n测试 {admin_info['role']} 登录...")
|
|
print(f" 邮箱: {admin_info['email']}")
|
|
|
|
try:
|
|
resp = requests.post(
|
|
f"{BASE_URL}/api/auth/login",
|
|
json={
|
|
"email": admin_info["email"],
|
|
"password": admin_info["password"],
|
|
"role": admin_info["login_role"]
|
|
},
|
|
timeout=5
|
|
)
|
|
|
|
if resp.status_code == 200:
|
|
data = resp.json()
|
|
token = data.get("data", {}).get("token")
|
|
user_info = data.get("data", {}).get("user", {})
|
|
print(f" ✓ 登录成功")
|
|
print(f" 角色: {user_info.get('role', 'N/A')}")
|
|
if user_info.get('channelId'):
|
|
print(f" 渠道ID: {user_info.get('channelId')}")
|
|
return True, token
|
|
else:
|
|
error = resp.json().get("detail", resp.text)
|
|
print(f" ✗ 登录失败: {error}")
|
|
return False, None
|
|
except Exception as e:
|
|
print(f" ✗ 登录出错: {e}")
|
|
return False, None
|
|
|
|
def main():
|
|
print("="*70)
|
|
print("测试所有管理员账户登录")
|
|
print("="*70)
|
|
|
|
results = []
|
|
for admin in ADMINS:
|
|
success, token = test_admin_login(admin)
|
|
results.append({
|
|
"role": admin["role"],
|
|
"email": admin["email"],
|
|
"success": success
|
|
})
|
|
|
|
print("\n" + "="*70)
|
|
print("测试结果汇总")
|
|
print("="*70)
|
|
print(f"\n{'角色':<20} {'邮箱':<35} {'状态'}")
|
|
print("-" * 70)
|
|
|
|
for result in results:
|
|
status = "✓ 成功" if result["success"] else "✗ 失败"
|
|
print(f"{result['role']:<20} {result['email']:<35} {status}")
|
|
|
|
success_count = sum(1 for r in results if r["success"])
|
|
print(f"\n总计: {success_count}/{len(results)} 个账户登录成功")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|