157 lines
5.2 KiB
Python
157 lines
5.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Street Lingo Platform Setup Test
|
|
Tests backend functionality and API endpoints
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
import sys
|
|
from typing import Dict, Any
|
|
|
|
def test_backend_health():
|
|
"""Test if backend is running and healthy"""
|
|
try:
|
|
response = requests.get("http://localhost:8000/api/health", timeout=5)
|
|
if response.status_code == 200:
|
|
print("✅ Backend health check passed")
|
|
return True
|
|
else:
|
|
print(f"❌ Backend health check failed: {response.status_code}")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ Backend not reachable: {e}")
|
|
return False
|
|
|
|
def test_scenarios_api():
|
|
"""Test scenarios API endpoints"""
|
|
print("\n🧪 Testing Scenarios API...")
|
|
|
|
# Test Indonesian scenarios
|
|
try:
|
|
response = requests.get("http://localhost:8000/api/scenarios/indonesian", timeout=5)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
scenarios = list(data.keys())
|
|
print(f"✅ Indonesian scenarios: {scenarios}")
|
|
else:
|
|
print(f"❌ Indonesian scenarios failed: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"❌ Indonesian scenarios error: {e}")
|
|
|
|
# Test German scenarios
|
|
try:
|
|
response = requests.get("http://localhost:8000/api/scenarios/german", timeout=5)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
scenarios = list(data.keys())
|
|
print(f"✅ German scenarios: {scenarios}")
|
|
else:
|
|
print(f"❌ German scenarios failed: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"❌ German scenarios error: {e}")
|
|
|
|
# Test all scenarios
|
|
try:
|
|
response = requests.get("http://localhost:8000/api/scenarios", timeout=5)
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
languages = list(data.keys())
|
|
print(f"✅ All scenarios endpoint: {languages}")
|
|
else:
|
|
print(f"❌ All scenarios failed: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"❌ All scenarios error: {e}")
|
|
|
|
def test_translation_api():
|
|
"""Test translation API"""
|
|
print("\n🧪 Testing Translation API...")
|
|
|
|
test_data = {
|
|
"text": "Hallo, wie geht es dir?",
|
|
"source_language": "de",
|
|
"target_language": "en"
|
|
}
|
|
|
|
try:
|
|
response = requests.post(
|
|
"http://localhost:8000/api/translate",
|
|
json=test_data,
|
|
timeout=10
|
|
)
|
|
if response.status_code == 200:
|
|
result = response.json()
|
|
print(f"✅ Translation API works: '{test_data['text']}' → '{result['translation']}'")
|
|
else:
|
|
print(f"❌ Translation API failed: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"❌ Translation API error: {e}")
|
|
|
|
def test_frontend_accessibility():
|
|
"""Test if frontend apps are accessible"""
|
|
print("\n🧪 Testing Frontend Accessibility...")
|
|
|
|
# Test Indonesian app
|
|
try:
|
|
response = requests.get("http://localhost:3000", timeout=5)
|
|
if response.status_code == 200:
|
|
print("✅ Indonesian app (port 3000) is accessible")
|
|
else:
|
|
print(f"❌ Indonesian app failed: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"⚠️ Indonesian app not accessible: {e}")
|
|
|
|
# Test German app
|
|
try:
|
|
response = requests.get("http://localhost:3001", timeout=5)
|
|
if response.status_code == 200:
|
|
print("✅ German app (port 3001) is accessible")
|
|
else:
|
|
print(f"❌ German app failed: {response.status_code}")
|
|
except Exception as e:
|
|
print(f"⚠️ German app not accessible: {e}")
|
|
|
|
def print_summary():
|
|
"""Print setup summary"""
|
|
print("\n" + "="*50)
|
|
print("🌍 STREET LINGO PLATFORM SETUP SUMMARY")
|
|
print("="*50)
|
|
print("\n📱 Access Your Apps:")
|
|
print(" 🇮🇩 Indonesian: http://localhost:3000")
|
|
print(" 🇩🇪 German: http://localhost:3001")
|
|
print("\n🔧 Backend API:")
|
|
print(" 📡 Main API: http://localhost:8000")
|
|
print(" 📊 API Docs: http://localhost:8000/docs")
|
|
print("\n🎯 Test Scenarios:")
|
|
print(" 🇮🇩 Indonesian: http://localhost:8000/api/scenarios/indonesian")
|
|
print(" 🇩🇪 German: http://localhost:8000/api/scenarios/german")
|
|
print("\n💡 Next Steps:")
|
|
print(" 1. Open the apps in your browser")
|
|
print(" 2. Grant microphone permissions")
|
|
print(" 3. Try a conversation scenario")
|
|
print(" 4. Check the API docs for more endpoints")
|
|
print("\n🚀 Happy Learning!")
|
|
|
|
def main():
|
|
"""Main test function"""
|
|
print("🧪 STREET LINGO PLATFORM TEST")
|
|
print("=" * 40)
|
|
|
|
# Test backend health
|
|
if not test_backend_health():
|
|
print("\n❌ Backend is not running. Please start it first:")
|
|
print(" cd backend && python main.py")
|
|
sys.exit(1)
|
|
|
|
# Test API endpoints
|
|
test_scenarios_api()
|
|
test_translation_api()
|
|
|
|
# Test frontend accessibility
|
|
test_frontend_accessibility()
|
|
|
|
# Print summary
|
|
print_summary()
|
|
|
|
if __name__ == "__main__":
|
|
main() |