energensy contacts, dashboard
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
149
test_mobile_formats.py
Normal file
149
test_mobile_formats.py
Normal file
@@ -0,0 +1,149 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import requests
|
||||
import time
|
||||
|
||||
def test_mobile_app_formats():
|
||||
"""Test various data formats that mobile apps commonly send"""
|
||||
base_url = "http://192.168.0.103:8000"
|
||||
|
||||
# Common mobile app data format issues
|
||||
test_cases = [
|
||||
{
|
||||
"name": "Android app - nested data structure",
|
||||
"data": {
|
||||
"user": {
|
||||
"email": "testuser@example.com",
|
||||
"password": "SecurePass123"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "iOS app - camelCase fields",
|
||||
"data": {
|
||||
"emailAddress": "testuser@example.com",
|
||||
"userPassword": "SecurePass123"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "React Native - mixed case",
|
||||
"data": {
|
||||
"Email": "testuser@example.com",
|
||||
"Password": "SecurePass123"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Flutter app - snake_case",
|
||||
"data": {
|
||||
"user_email": "testuser@example.com",
|
||||
"user_password": "SecurePass123"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Mobile app with extra fields",
|
||||
"data": {
|
||||
"email": "testuser@example.com",
|
||||
"password": "SecurePass123",
|
||||
"device_id": "mobile123",
|
||||
"app_version": "1.0.0",
|
||||
"platform": "android"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Empty string fields (common mobile bug)",
|
||||
"data": {
|
||||
"email": "",
|
||||
"username": "",
|
||||
"password": "SecurePass123"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Null fields (another common mobile bug)",
|
||||
"data": {
|
||||
"email": None,
|
||||
"username": None,
|
||||
"password": "SecurePass123"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Correct format",
|
||||
"data": {
|
||||
"email": "testuser@example.com",
|
||||
"password": "SecurePass123"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json",
|
||||
"User-Agent": "WomenSafetyApp/1.0 (Android)"
|
||||
}
|
||||
|
||||
print("📱 Testing mobile app data formats on 192.168.0.103")
|
||||
print("=" * 70)
|
||||
|
||||
for i, test_case in enumerate(test_cases, 1):
|
||||
print(f"\n{i}. 🧪 {test_case['name']}")
|
||||
print("-" * 50)
|
||||
|
||||
try:
|
||||
# Send request
|
||||
response = requests.post(
|
||||
f"{base_url}/api/v1/auth/login",
|
||||
json=test_case["data"],
|
||||
headers=headers,
|
||||
timeout=10
|
||||
)
|
||||
|
||||
print(f"📤 Request: {json.dumps(test_case['data'], indent=2)}")
|
||||
print(f"📊 Status: {response.status_code}")
|
||||
|
||||
# Analyze response
|
||||
if response.status_code == 200:
|
||||
print("✅ SUCCESS - Login worked!")
|
||||
try:
|
||||
token_data = response.json()
|
||||
print(f"🔐 Token type: {token_data.get('token_type')}")
|
||||
except:
|
||||
pass
|
||||
|
||||
elif response.status_code == 422:
|
||||
print("❌ VALIDATION ERROR")
|
||||
try:
|
||||
error_data = response.json()
|
||||
if "detail" in error_data:
|
||||
detail = error_data["detail"]
|
||||
if isinstance(detail, list):
|
||||
print("📝 Validation issues:")
|
||||
for error in detail:
|
||||
field = error.get("loc", [])[-1] if error.get("loc") else "unknown"
|
||||
msg = error.get("msg", "Unknown error")
|
||||
input_val = error.get("input", "")
|
||||
print(f" • Field '{field}': {msg} (input: {input_val})")
|
||||
else:
|
||||
print(f"📝 Error: {detail}")
|
||||
except Exception as e:
|
||||
print(f"📝 Raw error: {response.text}")
|
||||
|
||||
elif response.status_code == 401:
|
||||
print("🔒 AUTHENTICATION FAILED - Wrong credentials")
|
||||
|
||||
else:
|
||||
print(f"🚫 OTHER ERROR: {response.status_code}")
|
||||
print(f"📝 Response: {response.text[:200]}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"💥 REQUEST ERROR: {str(e)}")
|
||||
|
||||
time.sleep(0.5)
|
||||
|
||||
print(f"\n{'='*70}")
|
||||
print("📋 SUMMARY:")
|
||||
print("• Check which format works correctly")
|
||||
print("• Compare with mobile app's actual request format")
|
||||
print("• Update mobile app to match working format")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_mobile_app_formats()
|
||||
Reference in New Issue
Block a user