Skip to content

Commit

Permalink
chore: added unit test to turn on psu
Browse files Browse the repository at this point in the history
  • Loading branch information
builder555 committed Nov 8, 2024
1 parent 096e97f commit 3049aef
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions server/api/test_server.py
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -26,3 +29,15 @@ def test_serves_html_on_root():
response = client.get("/")
assert response.status_code == 200
assert "<html>" 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()

0 comments on commit 3049aef

Please sign in to comment.