forked from BerriAI/litellm
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_bulk_update_all_users.py
More file actions
126 lines (103 loc) · 3.93 KB
/
test_bulk_update_all_users.py
File metadata and controls
126 lines (103 loc) · 3.93 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
"""
Test script for the new bulk update "all users" functionality.
This script demonstrates how to use the enhanced bulk_update endpoint
to update all users in the system at once.
"""
import requests
import json
# Configuration
PROXY_BASE_URL = "http://localhost:4000"
ACCESS_TOKEN = "sk-1234" # Replace with your actual access token
def test_bulk_update_specific_users():
"""Test the existing functionality - updating specific users."""
print("=== Testing bulk update for specific users ===")
url = f"{PROXY_BASE_URL}/user/bulk_update"
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "application/json",
}
# Example payload for updating specific users
payload = {
"users": [
{"user_id": "user1", "user_role": "internal_user", "max_budget": 100.0},
{
"user_email": "user2@example.com",
"user_role": "internal_user_viewer",
"max_budget": 50.0,
},
]
}
try:
response = requests.post(url, headers=headers, json=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
except Exception as e:
print(f"Error: {e}")
def test_bulk_update_all_users():
"""Test the new functionality - updating all users."""
print("\n=== Testing bulk update for ALL users ===")
url = f"{PROXY_BASE_URL}/user/bulk_update"
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "application/json",
}
# Example payload for updating ALL users
payload = {
"all_users": True,
"user_updates": {"user_role": "internal_user", "max_budget": 75.0},
}
try:
response = requests.post(url, headers=headers, json=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
except Exception as e:
print(f"Error: {e}")
def test_validation_errors():
"""Test validation errors for invalid payloads."""
print("\n=== Testing validation errors ===")
url = f"{PROXY_BASE_URL}/user/bulk_update"
headers = {
"Authorization": f"Bearer {ACCESS_TOKEN}",
"Content-Type": "application/json",
}
# Test 1: Empty payload
print("Test 1: Empty payload")
try:
response = requests.post(url, headers=headers, json={})
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
except Exception as e:
print(f"Error: {e}")
# Test 2: Both users and all_users specified
print("\nTest 2: Both users and all_users specified")
try:
payload = {
"users": [{"user_id": "user1", "user_role": "internal_user"}],
"all_users": True,
"user_updates": {"user_role": "internal_user"},
}
response = requests.post(url, headers=headers, json=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
except Exception as e:
print(f"Error: {e}")
# Test 3: all_users=True but no user_updates
print("\nTest 3: all_users=True but no user_updates")
try:
payload = {"all_users": True}
response = requests.post(url, headers=headers, json=payload)
print(f"Status Code: {response.status_code}")
print(f"Response: {response.json()}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
print("Bulk Update All Users Test Script")
print("==================================")
# Note: Comment out tests as needed
# test_bulk_update_specific_users()
# test_bulk_update_all_users() # BE CAREFUL with this one!
test_validation_errors()
print("\n✅ Test script completed!")
print("\nNOTE: The 'test_bulk_update_all_users()' function is commented out")
print("to prevent accidentally updating all users. Uncomment it carefully!")