45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
|
|
#!/usr/bin/env python
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
import asyncio
|
||
|
|
import sys
|
||
|
|
sys.path.insert(0, 'ruoyi-fastapi-backend')
|
||
|
|
|
||
|
|
import httpx
|
||
|
|
|
||
|
|
async def test():
|
||
|
|
async with httpx.AsyncClient() as client:
|
||
|
|
# 登录
|
||
|
|
login_resp = await client.post(
|
||
|
|
"http://localhost:9100/login",
|
||
|
|
data={"username": "admin", "password": "admin123"}
|
||
|
|
)
|
||
|
|
token = login_resp.json()["token"]
|
||
|
|
print(f"Token: {token[:20]}...")
|
||
|
|
|
||
|
|
# 调用详情接口
|
||
|
|
headers = {"Authorization": f"Bearer {token}"}
|
||
|
|
|
||
|
|
# 测试 receipt_id=1161
|
||
|
|
print("\nTesting GET /warehouse/receipt/1161...")
|
||
|
|
resp = await client.get(
|
||
|
|
"http://localhost:9100/warehouse/receipt/1161",
|
||
|
|
headers=headers
|
||
|
|
)
|
||
|
|
print(f"Status: {resp.status_code}")
|
||
|
|
print(f"Content-Type: {resp.headers.get('content-type')}")
|
||
|
|
print(f"Response length: {len(resp.text)}")
|
||
|
|
print(f"Response preview: {resp.text[:500]}")
|
||
|
|
|
||
|
|
# 检查是否能解析为 JSON
|
||
|
|
try:
|
||
|
|
data = resp.json()
|
||
|
|
print(f"\nJSON parsed successfully")
|
||
|
|
print(f"Code: {data.get('code')}")
|
||
|
|
print(f"Msg: {data.get('msg')}")
|
||
|
|
if data.get('code') == 200:
|
||
|
|
print(f"Data keys: {list(data.get('data', {}).keys())[:10]}")
|
||
|
|
except Exception as e:
|
||
|
|
print(f"\nJSON parse error: {e}")
|
||
|
|
|
||
|
|
asyncio.run(test())
|