All checks were successful
continuous-integration/drone/push Build is passing
106 lines
3.4 KiB
Python
106 lines
3.4 KiB
Python
#!/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() |