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'
def test_encode(ds: IdexDatastream): data = {'some': 'data', 'arr': [{'k1': 'v1'}, {'k2': 'v2'}]} expected = '{"some":"data","arr":[{"k1":"v1"},{"k2":"v2"}]}' assert ds._encode(data) == expected