"""
测试管理员登录
"""
import requests

BASE_URL = "http://localhost:8000/api"

def test_login(username, password):
    """测试登录"""
    print(f"测试登录: {username}")
    
    response = requests.post(f"{BASE_URL}/users/login", data={
        "username": username,
        "password": password
    })
    
    if response.status_code == 200:
        result = response.json()
        print(f"[OK] 登录成功")
        print(f"Token: {result['access_token'][:50]}...")
        return result['access_token']
    else:
        print(f"[ERROR] 登录失败: {response.status_code}")
        print(f"响应: {response.text}")
        return None

if __name__ == "__main__":
    print("="*60)
    print("测试管理员登录")
    print("="*60)
    
    # 测试 admin/admin123
    token = test_login("admin", "admin123")
    
    if not token:
        # 尝试其他密码
        print("\n尝试其他密码...")
        token = test_login("admin", "123456")
