async def test_connect_to_server(tmpdir): # Setup client = NetworkClient(Path(tmpdir), {"server_address": "http://localhost:5000", "socketio_path": "/path"}) async def connect(*args, **kwargs): client._waiting_for_on_connect.set_result(True) client.sio = MagicMock() client.sio.connect = AsyncMock(side_effect=connect) client.sio.connected = False # Run await client.connect_to_server() # Assert assert client.connection_state == ConnectionState.Connecting client.sio.connect.assert_awaited_once_with("http://localhost:5000", socketio_path="/path", transports=["websocket"], headers={"X-Randovania-Version": randovania.VERSION})
async def test_leave_game_session(client: NetworkClient, permanent: bool): client._emit_with_result = AsyncMock() client._current_game_session_meta = MagicMock() client._current_game_session_meta.id = 1234 client._current_user = MagicMock() client._current_user.id = 5678 # Run await client.leave_game_session(permanent) # Assert calls = [call("disconnect_game_session", 1234)] if permanent: calls.insert( 0, call("game_session_admin_player", (1234, 5678, SessionAdminUserAction.KICK.value, None))) client._emit_with_result.assert_has_awaits(calls) assert client._current_game_session_meta is None
async def test_on_connect_restore(tmpdir, valid_session: bool): client = NetworkClient(Path(tmpdir), {"server_address": "http://*****:*****@30VtI6Ba{' } } else: call_result = InvalidSession().as_json client.sio = MagicMock() client.sio.call = AsyncMock(return_value=call_result) # Run await client.on_connect() # Assert client.sio.call.assert_awaited_once_with("restore_user_session", (b"foo", None), namespace=None, timeout=30) if valid_session: assert client.connection_state == ConnectionState.Connected assert session_data_path.read_bytes() == b"new_bytes" else: assert client.connection_state == ConnectionState.ConnectedNotLogged assert not session_data_path.is_file()
def _client(tmpdir): return NetworkClient(Path(tmpdir), {"server_address": "http://localhost:5000"})
def test_update_timeout_with_increase(client: NetworkClient): # Run client._update_timeout_with(5.0, False) # Assert assert client._current_timeout == 40
def __init__(self, user_data_dir: Path): super().__init__() NetworkClient.__init__(self, user_data_dir.joinpath("network_client"), randovania.get_configuration()) from randovania.gui.lib import common_qt_lib common_qt_lib.set_default_window_icon(self)