40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
|
|
import requests, json, sys, traceback
|
||
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
||
|
|
|
||
|
|
# Login
|
||
|
|
r = requests.post('http://localhost:9099/login', data={'username':'admin','password':'admin123'})
|
||
|
|
data = r.json()
|
||
|
|
token = data.get('token')
|
||
|
|
print(f"Login: {r.status_code}")
|
||
|
|
|
||
|
|
# Get detail of receipt_id=6
|
||
|
|
headers = {'Authorization': f'Bearer {token}'}
|
||
|
|
rid = 6
|
||
|
|
print(f"\nGET /warehouse/receipt/{rid}")
|
||
|
|
r3 = requests.get(f'http://localhost:9099/warehouse/receipt/{rid}', headers=headers)
|
||
|
|
print(f"Status: {r3.status_code}")
|
||
|
|
print(f"Full response: {r3.text[:1000]}")
|
||
|
|
|
||
|
|
# Also try PUT (edit)
|
||
|
|
print(f"\n--- Test PUT (edit) ---")
|
||
|
|
# First get the current data
|
||
|
|
if r3.status_code == 200:
|
||
|
|
detail = r3.json()
|
||
|
|
if detail.get('code') == 200:
|
||
|
|
receipt_data = detail['data']
|
||
|
|
print(f"Receipt data keys: {list(receipt_data.keys())}")
|
||
|
|
# Try to update
|
||
|
|
edit_data = {
|
||
|
|
'receiptId': receipt_data['receiptId'],
|
||
|
|
'receiptNo': receipt_data.get('receiptNo'),
|
||
|
|
'clientUnit': receipt_data.get('clientUnit', ''),
|
||
|
|
'clientContact': receipt_data.get('clientContact', ''),
|
||
|
|
'receiptDate': receipt_data.get('receiptDate', ''),
|
||
|
|
'status': receipt_data.get('status', '0'),
|
||
|
|
}
|
||
|
|
r4 = requests.put('http://localhost:9099/warehouse/receipt', headers=headers, json=edit_data)
|
||
|
|
print(f"PUT Status: {r4.status_code}")
|
||
|
|
print(f"PUT Response: {r4.text[:500]}")
|
||
|
|
else:
|
||
|
|
print(f"Cannot test PUT - GET failed: {detail.get('msg')}")
|