106 lines
2.8 KiB
Python
106 lines
2.8 KiB
Python
import requests
|
||
import json
|
||
|
||
# 配置
|
||
BASE_URL = "http://localhost:8080"
|
||
LOGIN_URL = f"{BASE_URL}/login/test"
|
||
LIST_URL = f"{BASE_URL}/ccdi/staffFmyRelation/list"
|
||
|
||
# 测试账号
|
||
test_user = {
|
||
"username": "admin",
|
||
"password": "admin123"
|
||
}
|
||
|
||
def test_fix():
|
||
"""测试修复是否成功"""
|
||
print("=" * 60)
|
||
print("开始测试员工家庭关系接口修复")
|
||
print("=" * 60)
|
||
|
||
# Step 1: 获取token
|
||
print("\n[1/2] 正在登录获取token...")
|
||
|
||
headers = {
|
||
"Content-Type": "application/json"
|
||
}
|
||
|
||
login_response = requests.post(LOGIN_URL, json=test_user, headers=headers)
|
||
|
||
if login_response.status_code != 200:
|
||
print(f"❌ 登录失败: {login_response.status_code}")
|
||
print(login_response.text)
|
||
return False
|
||
|
||
login_data = login_response.json()
|
||
if login_data.get("code") != 200:
|
||
print(f"❌ 登录失败: {login_data.get('msg')}")
|
||
return False
|
||
|
||
token = login_data.get("token")
|
||
print(f"✅ 登录成功,获取到token: {token[:20]}...")
|
||
|
||
# Step 2: 调用分页查询接口
|
||
print("\n[2/2] 正在测试分页查询接口...")
|
||
|
||
headers = {
|
||
"Authorization": f"Bearer {token}"
|
||
}
|
||
|
||
params = {
|
||
"pageNum": 1,
|
||
"pageSize": 10,
|
||
"isEmpFamily": 1
|
||
}
|
||
|
||
list_response = requests.get(LIST_URL, params=params, headers=headers)
|
||
|
||
print(f"\n响应状态码: {list_response.status_code}")
|
||
|
||
if list_response.status_code != 200:
|
||
print(f"❌ 接口调用失败")
|
||
print(list_response.text)
|
||
return False
|
||
|
||
result = list_response.json()
|
||
|
||
# 保存完整响应
|
||
with open("test_result.json", "w", encoding="utf-8") as f:
|
||
json.dump(result, f, ensure_ascii=False, indent=2)
|
||
|
||
print(f"\n完整响应已保存到 test_result.json")
|
||
|
||
if result.get("code") == 200:
|
||
rows = result.get("rows", [])
|
||
total = result.get("total", 0)
|
||
|
||
print(f"✅ 接口调用成功!")
|
||
print(f" - 数据总数: {total}")
|
||
print(f" - 当前页记录数: {len(rows)}")
|
||
|
||
if rows:
|
||
print(f"\n示例数据 (第一条):")
|
||
first_row = rows[0]
|
||
for key, value in first_row.items():
|
||
if key not in ["createTime", "updateTime"]:
|
||
print(f" {key}: {value}")
|
||
|
||
print("\n" + "=" * 60)
|
||
print("✅ 修复验证成功!数据库字段映射问题已解决")
|
||
print("=" * 60)
|
||
return True
|
||
else:
|
||
print(f"❌ 接口返回错误: {result.get('msg')}")
|
||
print(f"错误详情: {result}")
|
||
return False
|
||
|
||
if __name__ == "__main__":
|
||
try:
|
||
success = test_fix()
|
||
exit(0 if success else 1)
|
||
except Exception as e:
|
||
print(f"\n❌ 测试过程中发生异常: {str(e)}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
exit(1)
|