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)
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')