コード例 #1
0
def test_decode(ds: IdexDatastream):
    assert ds._decode('{"some":"data"}') == {'some': 'data'}
    assert ds._decode('{"payload": "{\\"some\\": \\"data\\"}"}') == {
        'payload': {
            'some': 'data'
        }
    }
    assert ds._decode('{"warnings": "[\\"warn1\\", \\"warn2\\"]"}') == {
        'warnings': ['warn1', 'warn2']
    }
コード例 #2
0
def test_process_message_sub_response(ds: IdexDatastream):
    msg = '{"payload":"{"some": "data"}"}'
    decoded_msg = {1: 2}
    sub_response = {3: 4}

    ds._decode = Mock()
    ds._decode.return_value = decoded_msg

    ds._check_warnings = Mock()
    ds._check_errors = Mock()
    ds._check_sid = Mock()

    ds.sub_manager.is_sub_response = Mock()
    ds.sub_manager.is_sub_response.return_value = True

    ds.sub_manager.process_sub_response = Mock()
    ds.sub_manager.process_sub_response.return_value = sub_response

    result = ds._process_message(msg)

    ds._decode.assert_called_with(msg)
    ds.sub_manager.is_sub_response.assert_called_once_with(decoded_msg)
    ds.sub_manager.process_sub_response.assert_called_once_with(decoded_msg)
    ds._check_warnings.assert_called_once_with(decoded_msg)
    ds._check_errors.assert_called_once_with(decoded_msg)
    ds._check_sid.assert_called_once_with(decoded_msg)

    assert result == sub_response