08ea5fbe98
添加用户管理视图、API和状态管理文件
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""
|
|
测试API客户端
|
|
"""
|
|
|
|
from core.api_client import APIClient
|
|
from core.exceptions import APITimeoutError
|
|
|
|
print('测试API客户端...')
|
|
|
|
# 测试1: 创建客户端
|
|
print('\n1. 测试创建客户端:')
|
|
client = APIClient(base_url="http://localhost:8080")
|
|
print(f' 基础URL: {client.base_url}')
|
|
print(f' 超时时间: {client.timeout}秒')
|
|
|
|
# 测试2: 请求头
|
|
print('\n2. 测试请求头:')
|
|
headers = client.get_headers()
|
|
print(f' Content-Type: {headers.get("Content-Type")}')
|
|
print(f' Authorization: {headers.get("Authorization", "未设置")}')
|
|
|
|
# 测试3: 带认证的客户端
|
|
print('\n3. 测试带认证的客户端:')
|
|
client_with_auth = APIClient(
|
|
base_url="http://localhost:8080",
|
|
token="test_token_12345"
|
|
)
|
|
headers = client_with_auth.get_headers()
|
|
print(f' Authorization: {headers.get("Authorization")}')
|
|
|
|
# 测试4: 404错误处理
|
|
print('\n4. 测试404错误处理:')
|
|
try:
|
|
response = client.get("/api/nonexistent")
|
|
print(f' 状态码: {response.get("status")}')
|
|
print(f' 错误信息: {response.get("error")}')
|
|
except Exception as e:
|
|
print(f' 请求失败(预期): {str(e)}')
|
|
|
|
print('\n✅ API客户端测试通过!')
|