#!/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()