This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Timmy-time-dashboard/tests/test_websocket.py
Alexander Payne 3463f4e4a4 fix: rename src/websocket to src/ws_manager to avoid websocket-client clash
selenium depends on websocket-client which installs a top-level
`websocket` package that shadows our src/websocket/ module on CI.
Renaming to ws_manager eliminates the conflict entirely — no more
sys.path hacks needed in conftest or Selenium tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 07:57:28 -05:00

32 lines
850 B
Python

"""Tests for ws_manager/handler.py — WebSocket manager."""
import json
import pytest
from ws_manager.handler import WebSocketManager, WSEvent
def test_ws_event_to_json():
event = WSEvent(event="test", data={"key": "val"}, timestamp="2026-01-01T00:00:00Z")
j = json.loads(event.to_json())
assert j["event"] == "test"
assert j["data"]["key"] == "val"
def test_ws_manager_initial_state():
mgr = WebSocketManager()
assert mgr.connection_count == 0
assert mgr.event_history == []
@pytest.mark.asyncio
async def test_ws_manager_event_history_limit():
"""History is trimmed to max_history after broadcasts."""
mgr = WebSocketManager()
mgr._max_history = 5
for i in range(10):
await mgr.broadcast(f"e{i}", {})
assert len(mgr.event_history) == 5
assert mgr.event_history[0].event == "e5"