Esempio n. 1
0
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'})
Esempio n. 2
0
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'