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
def test_check_error_not_exists(ds: IdexDatastream): msg = {'result': 'success'} ds._check_errors(msg)
def test_check_error_exists(ds: IdexDatastream): msg = {'result': 'error', 'payload': {'message': 'error message'}} with pytest.raises(IdexDataStreamError): ds._check_errors(msg)