diff --git a/server/api/test_server.py b/server/api/test_server.py index 9b91eb2..33a4330 100644 --- a/server/api/test_server.py +++ b/server/api/test_server.py @@ -1,6 +1,9 @@ import os import pytest from fastapi.testclient import TestClient +import json +from unittest.mock import patch +from unittest.mock import MagicMock os.environ["NO_DEVICE"] = "1" @@ -26,3 +29,15 @@ def test_serves_html_on_root(): response = client.get("/") assert response.status_code == 200 assert "" in response.text + + +@pytest.mark.asyncio +async def test_processes_power_on_command(): + mock_psu = MagicMock() + with patch("api.ws.psu", mock_psu): + with client.websocket_connect("/ws") as websocket: + websocket.send_text(json.dumps({"command": "POWER_ON"})) + response = websocket.receive_text() + response_data = json.loads(response) + assert response_data == {"status": "OK", "command": "POWER", "payload": True} + mock_psu.turn_on.assert_called_once()