feat: 初始化考培练系统项目
- 从服务器拉取完整代码 - 按框架规范整理项目结构 - 配置 Drone CI 测试环境部署 - 包含后端(FastAPI)、前端(Vue3)、管理端 技术栈: Vue3 + TypeScript + FastAPI + MySQL
This commit is contained in:
102
tests/test_update_profile.py
Normal file
102
tests/test_update_profile.py
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
测试更新用户个人信息(包括手机号、学校、专业)
|
||||
"""
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
# API配置
|
||||
API_BASE_URL = "http://localhost:8000"
|
||||
|
||||
def test_update_profile():
|
||||
"""测试更新个人信息"""
|
||||
|
||||
# 1. 先登录获取token
|
||||
print("1. 登录获取token...")
|
||||
login_data = {
|
||||
"username": "superadmin",
|
||||
"password": "Superadmin123!"
|
||||
}
|
||||
|
||||
response = requests.post(
|
||||
f"{API_BASE_URL}/api/v1/auth/login",
|
||||
json=login_data
|
||||
)
|
||||
|
||||
if response.status_code != 200:
|
||||
print(f"登录失败: {response.text}")
|
||||
return
|
||||
|
||||
token = response.json()["data"]["token"]["access_token"]
|
||||
print(f"登录成功,获取到token")
|
||||
|
||||
# 2. 获取当前用户信息
|
||||
print("\n2. 获取当前用户信息...")
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}"
|
||||
}
|
||||
|
||||
response = requests.get(
|
||||
f"{API_BASE_URL}/api/v1/users/me",
|
||||
headers=headers
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
user_data = response.json()["data"]
|
||||
print(f"当前用户信息:")
|
||||
print(f" 用户名: {user_data.get('username')}")
|
||||
print(f" 邮箱: {user_data.get('email')}")
|
||||
print(f" 手机号: {user_data.get('phone', '未设置')}")
|
||||
print(f" 学校: {user_data.get('school', '未设置')}")
|
||||
print(f" 专业: {user_data.get('major', '未设置')}")
|
||||
else:
|
||||
print(f"获取用户信息失败: {response.text}")
|
||||
return
|
||||
|
||||
# 3. 更新用户信息
|
||||
print("\n3. 更新用户信息(包括手机号、学校、专业)...")
|
||||
update_data = {
|
||||
"phone": "13800138000",
|
||||
"school": "清华大学",
|
||||
"major": "计算机科学与技术",
|
||||
"bio": "这是一个测试用的个人简介"
|
||||
}
|
||||
|
||||
response = requests.put(
|
||||
f"{API_BASE_URL}/api/v1/users/me",
|
||||
headers=headers,
|
||||
json=update_data
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("更新成功!")
|
||||
updated_data = response.json()["data"]
|
||||
print(f"更新后的信息:")
|
||||
print(f" 手机号: {updated_data.get('phone', '未设置')}")
|
||||
print(f" 学校: {updated_data.get('school', '未设置')}")
|
||||
print(f" 专业: {updated_data.get('major', '未设置')}")
|
||||
print(f" 个人简介: {updated_data.get('bio', '未设置')}")
|
||||
else:
|
||||
print(f"更新失败: {response.text}")
|
||||
|
||||
# 4. 再次获取信息验证
|
||||
print("\n4. 再次获取用户信息验证更新...")
|
||||
response = requests.get(
|
||||
f"{API_BASE_URL}/api/v1/users/me",
|
||||
headers=headers
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
user_data = response.json()["data"]
|
||||
print(f"验证结果:")
|
||||
print(f" 手机号: {user_data.get('phone', '未设置')}")
|
||||
print(f" 学校: {user_data.get('school', '未设置')}")
|
||||
print(f" 专业: {user_data.get('major', '未设置')}")
|
||||
else:
|
||||
print(f"获取用户信息失败: {response.text}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("测试更新用户个人信息API...")
|
||||
test_update_profile()
|
||||
print("\n测试完成!")
|
||||
Reference in New Issue
Block a user