import requests import json # Test the user edit endpoint base_url = "http://localhost:8000" # First, login as admin to get token login_data = { "username": "admin@example.com", # Update with your admin email "password": "admin123" # Update with your admin password } response = requests.post(f"{base_url}/auth/login", data=login_data) print("Login response:", response.status_code) if response.status_code == 200: token_data = response.json() access_token = token_data["access_token"] print("Access token obtained") # Try to edit user 5 headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } # Test with minimal data edit_data = { "email": "test@example.com" } print(f"\nTesting PUT /users/5/admin with data: {json.dumps(edit_data, indent=2)}") response = requests.put(f"{base_url}/users/5/admin", headers=headers, json=edit_data) print(f"Response status: {response.status_code}") print(f"Response body: {response.text}") if response.status_code != 200: print("\nTrying with all fields:") edit_data_full = { "first_name": "Test", "last_name": "User", "email": "test@example.com", "role": "artist", "is_approved": True, "is_admin": False } print(f"Data: {json.dumps(edit_data_full, indent=2)}") response = requests.put(f"{base_url}/users/5/admin", headers=headers, json=edit_data_full) print(f"Response status: {response.status_code}") print(f"Response body: {response.text}") else: print("Login failed:", response.text)