import pytest from unittest.mock import patch, MagicMock def test_start_engine(client): """Test starting the engine with a story id, without actually spawning process.""" with patch("subprocess.Popen") as mock_popen: mock_process = MagicMock() mock_process.pid = 12345 mock_popen.return_value = mock_process response = client.post("/api/engine/start", json={"story_id": "test_story"}) # Depending on if it sees 'asset_generator' in psutil, it might return 400 or 200 # If no other generator was running during test (which is expected): if response.status_code == 200: assert response.json()["status"] == "success" assert response.json()["pid"] == 12345 assert mock_popen.called else: # If the engine was truly running on the host, it skips Popen. assert response.status_code == 400 assert "Engine is already running" in response.json()["error"]