verify_system.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import socketio
  2. import requests
  3. import time
  4. import json
  5. # Test API
  6. def test_api():
  7. print("Testing API...")
  8. # Simulate a link request
  9. # Note: This will fail if the code is not in the server's memory,
  10. # but we just want to see if the endpoint is reachable.
  11. try:
  12. response = requests.post('http://localhost:5000/api/link', json={
  13. 'code': 'TESTCODE',
  14. 'uuid': 'test-uuid',
  15. 'username': 'TestPlayer'
  16. })
  17. print(f"API Response: {response.status_code} - {response.json()}")
  18. except Exception as e:
  19. print(f"API Connection Failed: {e}")
  20. # Test WebSocket
  21. def test_websocket():
  22. print("Testing WebSocket...")
  23. sio = socketio.Client()
  24. @sio.event
  25. def connect():
  26. print("WebSocket Connected!")
  27. # Send a test event
  28. sio.emit('game_event', {
  29. 'type': 'CHAT',
  30. 'player': 'TestPlayer',
  31. 'uuid': 'test-uuid',
  32. 'content': 'Hello from test script!'
  33. })
  34. print("Test event sent.")
  35. sio.disconnect()
  36. @sio.event
  37. def connect_error(data):
  38. print(f"WebSocket Connection Failed: {data}")
  39. try:
  40. sio.connect('http://localhost:5000')
  41. sio.wait()
  42. except Exception as e:
  43. print(f"WebSocket Error: {e}")
  44. if __name__ == "__main__":
  45. # Ensure the server is running before running this script
  46. test_api()
  47. test_websocket()