feat: Migrate to MySQL and add unified environment configuration
## Database Migration (SQLite → MySQL) - Add Alembic migration framework - Add 'tr_' prefix to all tables to avoid conflicts in shared database - Remove SQLite support, use MySQL exclusively - Add pymysql driver dependency - Change ad_token column to Text type for long JWT tokens ## Unified Environment Configuration - Centralize all hardcoded settings to environment variables - Backend: Extend Settings class in app/core/config.py - Frontend: Use Vite environment variables (import.meta.env) - Docker: Move credentials to environment variables - Update .env.example files with comprehensive documentation ## Test Organization - Move root-level test files to tests/ directory: - test_chat_room.py → tests/test_chat_room.py - test_websocket.py → tests/test_websocket.py - test_realtime_implementation.py → tests/test_realtime_implementation.py - Fix path references in test_realtime_implementation.py Breaking Changes: - CORS now requires explicit origins (no more wildcard) - All database tables renamed with 'tr_' prefix - SQLite no longer supported 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
98
tests/test_websocket.py
Executable file
98
tests/test_websocket.py
Executable file
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Test WebSocket realtime messaging functionality"""
|
||||
import asyncio
|
||||
import websockets
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
async def test_websocket_connection():
|
||||
"""Test basic WebSocket connection and message sending"""
|
||||
# Note: This is a simplified test. In production, you'd need proper authentication
|
||||
uri = "ws://localhost:8000/api/ws/test-room-123?token=test-user@example.com"
|
||||
|
||||
print("Connecting to WebSocket...")
|
||||
try:
|
||||
async with websockets.connect(uri) as websocket:
|
||||
print("✓ Connected to WebSocket!")
|
||||
|
||||
# Send a text message
|
||||
message = {
|
||||
"type": "message",
|
||||
"content": "Hello from WebSocket test!",
|
||||
"message_type": "text"
|
||||
}
|
||||
|
||||
print(f"\nSending message: {message}")
|
||||
await websocket.send(json.dumps(message))
|
||||
|
||||
# Wait for acknowledgment
|
||||
response = await asyncio.wait_for(websocket.recv(), timeout=5)
|
||||
response_data = json.loads(response)
|
||||
print(f"✓ Received response: {response_data}")
|
||||
|
||||
if response_data.get("type") == "ack":
|
||||
print(f" Message ID: {response_data.get('message_id')}")
|
||||
print(f" Sequence: {response_data.get('sequence_number')}")
|
||||
|
||||
except websockets.exceptions.InvalidStatusCode as e:
|
||||
if e.status_code == 4001:
|
||||
print("✗ Connection rejected: Not a member of room")
|
||||
print(" This is expected for test room without proper membership")
|
||||
else:
|
||||
print(f"✗ Connection failed with status {e.status_code}")
|
||||
except Exception as e:
|
||||
print(f"✗ Error: {e}")
|
||||
|
||||
|
||||
async def test_rest_api():
|
||||
"""Test REST API endpoints"""
|
||||
import aiohttp
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("Testing REST API Endpoints")
|
||||
print("=" * 50)
|
||||
|
||||
# Note: This requires authentication in production
|
||||
# For now, just test if endpoints are registered
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
# Test health check
|
||||
async with session.get("http://localhost:8000/health") as resp:
|
||||
if resp.status == 200:
|
||||
print("✓ Health check endpoint working")
|
||||
else:
|
||||
print(f"✗ Health check failed: {resp.status}")
|
||||
|
||||
# Test API docs
|
||||
async with session.get("http://localhost:8000/docs") as resp:
|
||||
if resp.status == 200:
|
||||
print("✓ API documentation accessible")
|
||||
else:
|
||||
print(f"✗ API docs failed: {resp.status}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=" * 50)
|
||||
print("WebSocket Realtime Messaging Test")
|
||||
print("=" * 50)
|
||||
|
||||
# Run REST API tests
|
||||
asyncio.run(test_rest_api())
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("Testing WebSocket Connection")
|
||||
print("=" * 50)
|
||||
|
||||
# Run WebSocket test
|
||||
asyncio.run(test_websocket_connection())
|
||||
|
||||
print("\n" + "=" * 50)
|
||||
print("Test Summary:")
|
||||
print("- Database tables created ✓")
|
||||
print("- Models and schemas defined ✓")
|
||||
print("- WebSocket manager implemented ✓")
|
||||
print("- Message service layer created ✓")
|
||||
print("- REST API endpoints registered ✓")
|
||||
print("- Server starts successfully ✓")
|
||||
print("=" * 50)
|
||||
Reference in New Issue
Block a user