def test_check_sid_raise(ds: IdexDatastream): ds._sid = 'sid:one' msg = {'sid': 'sid:another'} with pytest.raises(IdexResponseSidError): ds._check_sid(msg)
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_sid_not_raise(ds: IdexDatastream): ds._sid = 'sid:one' msg = {'sid': ds._sid} ds._check_sid(msg)