51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
|
|
#!/usr/bin/env python
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
测试账号创建API
|
||
|
|
"""
|
||
|
|
|
||
|
|
import requests
|
||
|
|
import json
|
||
|
|
|
||
|
|
# API基础URL
|
||
|
|
BASE_URL = "http://127.0.0.1:5000/api/v1"
|
||
|
|
|
||
|
|
def test_create_admin():
|
||
|
|
"""测试创建管理员账号"""
|
||
|
|
url = f"{BASE_URL}/admins"
|
||
|
|
|
||
|
|
# 测试数据
|
||
|
|
data = {
|
||
|
|
"username": "testuser123",
|
||
|
|
"email": "testuser123@example.com",
|
||
|
|
"password": "TestPass123!",
|
||
|
|
"role": 0,
|
||
|
|
"status": 1
|
||
|
|
}
|
||
|
|
|
||
|
|
headers = {
|
||
|
|
"Content-Type": "application/json"
|
||
|
|
}
|
||
|
|
|
||
|
|
print(f"Sending POST request to: {url}")
|
||
|
|
print(f"Request data: {json.dumps(data, indent=2, ensure_ascii=False)}")
|
||
|
|
|
||
|
|
try:
|
||
|
|
response = requests.post(url, json=data, headers=headers)
|
||
|
|
print(f"Response status code: {response.status_code}")
|
||
|
|
print(f"Response headers: {dict(response.headers)}")
|
||
|
|
|
||
|
|
if response.content:
|
||
|
|
try:
|
||
|
|
response_data = response.json()
|
||
|
|
print(f"Response JSON: {json.dumps(response_data, indent=2, ensure_ascii=False)}")
|
||
|
|
except json.JSONDecodeError:
|
||
|
|
print(f"Response text: {response.text}")
|
||
|
|
else:
|
||
|
|
print("Response is empty")
|
||
|
|
|
||
|
|
except requests.exceptions.RequestException as e:
|
||
|
|
print(f"Request failed: {e}")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
test_create_admin()
|