-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_suspend_api.py
More file actions
57 lines (48 loc) · 2.05 KB
/
test_suspend_api.py
File metadata and controls
57 lines (48 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""Test suspend API endpoint"""
import requests
import json
print("=" * 60)
print("SUSPEND REQUEST API TEST")
print("=" * 60)
# First, get a token by logging in as a PIN user
print("\n1. Logging in as PIN user...")
login_response = requests.post('http://localhost:5000/api/auth/login', json={
'username': 'pin_user1',
'password': 'password123',
'role_name': 'PIN'
})
if login_response.status_code == 200:
token = login_response.json()['data']['token']
print(f" ✓ Login successful, got token")
# Get list of requests to find an ACTIVE one
print("\n2. Getting list of ACTIVE requests...")
requests_response = requests.get(
'http://localhost:5000/api/requests?status=ACTIVE',
headers={'Authorization': f'Bearer {token}'}
)
if requests_response.status_code == 200:
requests_data = requests_response.json()
if requests_data['data']:
request_id = requests_data['data'][0]['id']
print(f" ✓ Found ACTIVE request ID: {request_id}")
# Now try to suspend it
print(f"\n3. Attempting to suspend request {request_id}...")
suspend_response = requests.put(
f'http://localhost:5000/api/requests/{request_id}/suspend',
headers={'Authorization': f'Bearer {token}'},
json={'reason': 'Test suspension from API test'}
)
print(f" Status Code: {suspend_response.status_code}")
print(f" Response: {json.dumps(suspend_response.json(), indent=2)}")
if suspend_response.status_code == 200:
print("\n ✓ SUSPEND API WORKS!")
else:
print("\n ✗ SUSPEND API FAILED")
else:
print(" ℹ️ No ACTIVE requests found to test suspension")
else:
print(f" ✗ Failed to get requests: {requests_response.status_code}")
else:
print(f" ✗ Login failed: {login_response.status_code}")
print(f" Response: {login_response.text}")
print("\n" + "=" * 60)