def test_sid(ds: IdexDatastream): ds._logger.info = Mock() ds._set_sid('some_sid') ds._logger.info.assert_called_once() assert ds._sid == 'some_sid'
def test_sid_equal(ds: IdexDatastream): ds._logger.info = Mock() ds._sid = 'some_sid' ds._set_sid('some_sid') ds._logger.info.assert_not_called() assert ds._sid == 'some_sid'
def test_compose_message(ds: IdexDatastream): ds._set_sid('somesid') assert ds._compose_message('somerid', 'somerequest', {'some': 'payload'}) == dict( rid='somerid', sid='somesid', request='somerequest', payload={'some': 'payload'})
def test_process_handshake_response(ds: IdexDatastream): ds._set_sid = Mock() with pytest.raises(IdexHandshakeException): ds._process_handshake_response({'result': 'not_success'}) with pytest.raises(IdexHandshakeException): ds._process_handshake_response({ 'result': 'success', 'request': 'not_handshake' }) ds._process_handshake_response({ 'result': 'success', 'request': 'handshake', 'sid': 'some_sid' }) ds._set_sid.assert_called_once_with('some_sid')
async def test_shake_hand(ds: IdexDatastream): ds._WS_VERSION = 'v1' ds._API_KEY = 'key' handshake_result = 'some result' ds._set_sid = Mock() ds.send_message = CoroutineMock() ds._wait_for_handshake_response = CoroutineMock() ds._wait_for_handshake_response.return_value = handshake_result ds._process_handshake_response = Mock() await ds._shake_hand() ds._set_sid.assert_called_with(None) ds.send_message.assert_awaited_once_with('handshake', dict(version='v1', key='key')) ds._wait_for_handshake_response.assert_awaited_once() ds._process_handshake_response.assert_called_once_with(handshake_result)