#!/usr/bin/env python3 import json import requests import time def test_fixed_endpoints(): """Test the fixed endpoints on production server""" base_url = "http://192.168.0.103:8000" # First, login to get access token print("๐Ÿ” Step 1: Login to get access token") login_response = requests.post( f"{base_url}/api/v1/auth/login", json={ "username": "Trevor1985", "password": "Cl0ud_1985!" }, headers={"Content-Type": "application/json"} ) if login_response.status_code != 200: print(f"โŒ Login failed: {login_response.status_code} - {login_response.text}") return token_data = login_response.json() access_token = token_data["access_token"] print(f"โœ… Login successful! Got access token.") # Test endpoints that were failing headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } test_endpoints = [ { "name": "User Profile", "url": "/api/v1/users/me", "method": "GET" }, { "name": "User Dashboard (was 404)", "url": "/api/v1/users/dashboard", "method": "GET" }, { "name": "Emergency Contacts (was 500)", "url": "/api/v1/users/me/emergency-contacts", "method": "GET" }, { "name": "Profile (alternative endpoint)", "url": "/api/v1/profile", "method": "GET" } ] print(f"\n๐Ÿงช Step 2: Testing fixed endpoints") print("=" * 60) for endpoint in test_endpoints: print(f"\n๐Ÿ“ Testing: {endpoint['name']}") print(f" URL: {endpoint['url']}") try: if endpoint['method'] == 'GET': response = requests.get( f"{base_url}{endpoint['url']}", headers=headers, timeout=10 ) print(f" Status: {response.status_code}") if response.status_code == 200: try: data = response.json() if endpoint['name'] == "User Dashboard (was 404)": print(f" โœ… Dashboard loaded! Emergency contacts: {data.get('emergency_contacts_count', 0)}") print(f" User: {data.get('user', {}).get('username', 'N/A')}") elif endpoint['name'] == "Emergency Contacts (was 500)": contacts = data if isinstance(data, list) else [] print(f" โœ… Emergency contacts loaded! Count: {len(contacts)}") else: print(f" โœ… Success! Got user data.") except: print(f" โœ… Success! (Response not JSON)") else: print(f" โŒ Failed: {response.text[:100]}...") except Exception as e: print(f" ๐Ÿ’ฅ Error: {str(e)}") time.sleep(0.5) print(f"\n{'='*60}") print("๐Ÿ“Š Summary:") print("โ€ข Login: โœ… Working") print("โ€ข Check each endpoint status above") print("โ€ข All 422 login errors should be resolved") print("โ€ข Database errors should be fixed") if __name__ == "__main__": print("๐Ÿš€ Testing fixed endpoints on production server 192.168.0.103") test_fixed_endpoints()