41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import requests
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
# 直接测试API端点,不进行登录验证
|
|||
|
|
def test_admin_api_directly():
|
|||
|
|
# API基础URL
|
|||
|
|
base_url = "http://127.0.0.1:5000"
|
|||
|
|
|
|||
|
|
# 测试数据
|
|||
|
|
admin_data = {
|
|||
|
|
"username": "direct_test_user",
|
|||
|
|
"email": "direct_test@example.com",
|
|||
|
|
"password": "direct_test123",
|
|||
|
|
"role": 0,
|
|||
|
|
"status": 1
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
print("直接测试创建管理员API...")
|
|||
|
|
print(f"发送数据: {json.dumps(admin_data, ensure_ascii=False)}")
|
|||
|
|
|
|||
|
|
# 直接发送POST请求到API端点
|
|||
|
|
response = requests.post(
|
|||
|
|
f"{base_url}/api/v1/admins",
|
|||
|
|
json=admin_data,
|
|||
|
|
headers={"Content-Type": "application/json"}
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
print(f"状态码: {response.status_code}")
|
|||
|
|
print(f"响应内容: {response.text}")
|
|||
|
|
|
|||
|
|
try:
|
|||
|
|
result = response.json()
|
|||
|
|
print(f"解析结果: {json.dumps(result, ensure_ascii=False, indent=2)}")
|
|||
|
|
except Exception as e:
|
|||
|
|
print(f"无法解析JSON响应: {e}")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
test_admin_api_directly()
|