def test_get_rid(ds: IdexDatastream): rid = ds._get_rid() assert isinstance(rid, str) assert rid.startswith('rid:') # Max accepted length is 50 characters. Your rid will be truncated if any longer than this. # Clients sending rid's which are longer than 50 characters risk eventual disconnects, blacklisting, or bans. assert len(rid) <= 50 rid2 = ds._get_rid() assert rid != rid2
async def test_create_connection(ds: IdexDatastream): ds._check_connection = CoroutineMock() ds._get_rid = Mock(return_value='rid:smth') ds._compose_message = Mock(return_value={'some': 'data'}) ds._ws = Mock() ds._ws.send = CoroutineMock() ds._encode = Mock() result = await ds.send_message('some_request', {'some': 'payload'}) ds._check_connection.assert_awaited_once() ds._get_rid.assert_called_once() ds._compose_message.assert_called_once_with('rid:smth', 'some_request', {'some': 'payload'}) ds._encode.assert_called_once_with({'some': 'data'}) ds._ws.send.assert_awaited_once() assert result == 'rid:smth'