Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /tests /unit /test_websocket.py
| import json | |
| from unittest.mock import AsyncMock, MagicMock, patch | |
| import pytest | |
| pytestmark = pytest.mark.asyncio(scope="module") | |
| async def test_websocket_connect(): | |
| mock_ws = AsyncMock() | |
| mock_ws.__aenter__.return_value = mock_ws | |
| with patch("websockets.connect") as mock_connect: | |
| mock_connect.return_value = mock_ws | |
| async with mock_connect("ws://test/ws") as ws: | |
| assert ws is not None | |
| async def test_websocket_send_receive(): | |
| mock_ws = AsyncMock() | |
| mock_ws.recv.return_value = json.dumps({"type": "response", "data": "ok"}) | |
| with patch("websockets.connect") as mock_connect: | |
| mock_connect.return_value.__aenter__.return_value = mock_ws | |
| await mock_ws.send(json.dumps({"type": "ping"})) | |
| response = await mock_ws.recv() | |
| data = json.loads(response) | |
| assert data["type"] == "response" | |
| async def test_websocket_malformed_message(): | |
| mock_ws = AsyncMock() | |
| mock_ws.recv.return_value = "not-json" | |
| with patch("websockets.connect") as mock_connect: | |
| mock_connect.return_value.__aenter__.return_value = mock_ws | |
| response = await mock_ws.recv() | |
| with pytest.raises(json.JSONDecodeError): | |
| json.loads(response) | |
Xet Storage Details
- Size:
- 1.24 kB
- Xet hash:
- d180a9fa0608e031dd1ca1480717e1cb97e1ad6bf79501c18f217498bfc9b8a8
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.