Files
ccdi/doc/implementation/scripts/test_import_simple.py
2026-02-09 14:28:25 +08:00

58 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import requests
import json
# 配置
BASE_URL = "http://localhost:8080"
LOGIN_URL = f"{BASE_URL}/login/test"
# 登录获取token
print("登录系统...")
login_data = {
"username": "admin",
"password": "admin123"
}
response = requests.post(LOGIN_URL, json=login_data)
token = response.json().get("token")
# 测试不同的导入方式
headers = {'Authorization': f'Bearer {token}'}
print("\n测试1: 直接POST请求无文件")
response = requests.post(
f"{BASE_URL}/dpc/intermediary/importPersonData",
headers=headers
)
print(f"状态码: {response.status_code}")
print(f"响应: {response.text[:200]}")
print("\n测试2: 带文件的POST请求URL参数")
files = {
'file': ('test.xlsx', open('doc/个人中介黑名单测试数据_1000条.xlsx', 'rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
}
response = requests.post(
f"{BASE_URL}/dpc/intermediary/importPersonData?updateSupport=false",
files=files,
headers=headers
)
print(f"状态码: {response.status_code}")
print(f"响应: {response.text[:500]}")
files['file'][1].close()
print("\n测试3: 带文件的POST请求Form数据")
files = {
'file': ('test.xlsx', open('doc/个人中介黑名单测试数据_1000条.xlsx', 'rb'), 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
}
data = {
'updateSupport': 'false'
}
response = requests.post(
f"{BASE_URL}/dpc/intermediary/importPersonData",
files=files,
data=data,
headers=headers
)
print(f"状态码: {response.status_code}")
print(f"响应: {response.text[:500]}")
files['file'][1].close()