ETest-Vue-FastAPI/test_api_call.py

45 lines
1.3 KiB
Python
Raw Normal View History

2026-04-15 19:06:01 +08:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import sys
import traceback
sys.path.insert(0, 'ruoyi-fastapi-backend')
async def test():
try:
import httpx
async with httpx.AsyncClient() as client:
# 登录
login_resp = await client.post(
"http://localhost:9100/login",
data={"username": "admin", "password": "admin123"}
)
print(f"Login status: {login_resp.status_code}")
resp_json = login_resp.json()
token = resp_json.get("token")
if not token:
print(f"Login failed: {resp_json}")
return
print(f"Token: {token[:20]}...")
# 调用详情接口
headers = {"Authorization": f"Bearer {token}"}
# 测试 receipt_id=1011
print("\nTesting /warehouse/receipt/1011...")
resp = await client.get(
"http://localhost:9100/warehouse/receipt/1011",
headers=headers
)
print(f"Status: {resp.status_code}")
print(f"Response: {resp.text[:500]}")
except Exception as e:
print(f"Error: {e}")
traceback.print_exc()
asyncio.run(test())