Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /randovania_randovania /test /server /test_socketio.py
| from __future__ import annotations | |
| from contextlib import AbstractContextManager, nullcontext | |
| from typing import TYPE_CHECKING, Any | |
| from unittest.mock import AsyncMock | |
| import pytest | |
| import socketio.exceptions | |
| from randovania.network_common import connection_headers, error | |
| from randovania.network_common.signals.server_signals import server_signal | |
| from test.server.sio_test_client import SocketIOTestClient | |
| if TYPE_CHECKING: | |
| from pytest_mock import MockerFixture | |
| async def sio_test_client_fixture(test_client): | |
| client = SocketIOTestClient(test_client.sa.sio) | |
| headers = {"HTTP_{}".format(k.upper().replace("-", "_")): v for k, v in connection_headers().items()} | |
| await client.connect(headers=headers) | |
| return client | |
| async def test_sio_connect_version_header( | |
| test_client, has_headers: bool, context: AbstractContextManager, is_dev_version | |
| ): | |
| client = SocketIOTestClient(test_client.sa.sio) | |
| headers = {} | |
| if has_headers: | |
| if not is_dev_version: | |
| headers = {"HTTP_{}".format(k.upper().replace("-", "_")): v for k, v in connection_headers().items()} | |
| headers["HTTP_X_RANDOVANIA_VERSION"] = "0.0.0" | |
| with context: | |
| await client.connect(headers=headers) | |
| assert client.is_connected() == has_headers | |
| async def test_sio_connect_client_check_error(test_client, mocker: MockerFixture, client_version_check_rval): | |
| mocker.patch( | |
| "randovania.server.client_check.check_client_version", | |
| return_value=client_version_check_rval, | |
| ) | |
| mocker.patch( | |
| "randovania.server.client_check.check_client_headers", | |
| return_value="Another error", | |
| ) | |
| mocker.patch("randovania.is_dev_version", return_value=False) | |
| client = SocketIOTestClient(test_client.sa.sio) | |
| headers = { | |
| "HTTP_X_RANDOVANIA_VERSION": "0.0.0", | |
| } | |
| expected = client_version_check_rval or "Another error" | |
| with pytest.raises(socketio.exceptions.ConnectionRefusedError, match=expected): | |
| await client.connect(headers=headers) | |
| async def test_on_success(side_effect: Any, rval: dict, test_client, sio_test_client): | |
| # Setup | |
| custom = server_signal("custom")(AsyncMock(side_effect=side_effect)) | |
| custom.register(test_client.sa, custom.fn) | |
| # Run | |
| result = await sio_test_client.emit("custom", callback=True) | |
| # Assert | |
| custom.fn.assert_awaited_once_with(test_client.sa, sio_test_client.sid) | |
| assert result == rval | |
Xet Storage Details
- Size:
- 3.08 kB
- Xet hash:
- b63878743b30702120fd695899e9c8d270a5f70535270e076e94c46fdcd7b710
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.