test_server.py 913 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. from __future__ import annotations
  2. import pytest
  3. from flask_socketio import SocketIOTestClient
  4. from sweagent.api.server import app, socketio
  5. @pytest.fixture
  6. def client():
  7. with app.test_client() as client:
  8. with app.app_context():
  9. yield client
  10. @pytest.fixture
  11. def socket_client():
  12. client = SocketIOTestClient(app, socketio)
  13. yield client
  14. client.disconnect()
  15. def test_index(client):
  16. """Test the index page"""
  17. response = client.get("/")
  18. assert response.status_code == 200
  19. def test_run_options(client):
  20. """Test the /run endpoint OPTIONS method for CORS preflight"""
  21. response = client.open("/run", method="OPTIONS")
  22. assert response.status_code == 200
  23. assert response.headers["Access-Control-Allow-Origin"] == "*"
  24. def test_stop(client):
  25. """Test the /stop endpoint"""
  26. response = client.get("/stop")
  27. assert response.status_code == 202