def test_changefeed_delete(mock_cursor_next, mock_changefeed_data): from bigchaindb.backend import get_changefeed, connect from bigchaindb.backend.changefeed import ChangeFeed conn = connect() mock_cursor_next.side_effect = [mock.DEFAULT] + mock_changefeed_data outpipe = Pipe() changefeed = get_changefeed(conn, 'backlog', ChangeFeed.DELETE) changefeed.outqueue = outpipe changefeed.run_forever() assert outpipe.get()['msg'] == 'seems like we have a delete here' assert outpipe.qsize() == 0
def test_changefeed_prefeed(mock_cursor_next, mock_changefeed_data): from bigchaindb.backend import get_changefeed, connect from bigchaindb.backend.changefeed import ChangeFeed conn = connect() mock_cursor_next.side_effect = [mock.DEFAULT] + mock_changefeed_data outpipe = Pipe() changefeed = get_changefeed(conn, 'backlog', ChangeFeed.INSERT, prefeed=[1, 2, 3]) changefeed.outqueue = outpipe changefeed.run_forever() assert outpipe.qsize() == 4
def test_changefeed_insert(mock_cursor_next, mock_changefeed_data): from bigchaindb.backend import get_changefeed, connect from bigchaindb.backend.changefeed import ChangeFeed # setup connection and mocks conn = connect() # mock the `next` method of the cursor to return the mocked data mock_cursor_next.side_effect = [mock.DEFAULT] + mock_changefeed_data outpipe = Pipe() changefeed = get_changefeed(conn, 'backlog', ChangeFeed.INSERT) changefeed.outqueue = outpipe changefeed.run_forever() assert outpipe.get()['msg'] == 'seems like we have an insert here' assert outpipe.qsize() == 0
def test_changefeed_update(mock_cursor_next, mock_cursor_find_one, mock_changefeed_data): from bigchaindb.backend import get_changefeed, connect from bigchaindb.backend.changefeed import ChangeFeed conn = connect() mock_cursor_next.side_effect = [mock.DEFAULT] + mock_changefeed_data mock_cursor_find_one.return_value = mock_changefeed_data[2]['o'] outpipe = Pipe() changefeed = get_changefeed(conn, 'backlog', ChangeFeed.UPDATE) changefeed.outqueue = outpipe changefeed.run_forever() assert outpipe.get()['msg'] == 'seems like we have an update here' assert outpipe.qsize() == 0 assert mock_cursor_find_one.called_once_with( {'_id': mock_changefeed_data[2]['o']}, {'_id': False})
def test_changefeed_multiple_operations(mock_cursor_next, mock_cursor_find_one, mock_changefeed_data): from bigchaindb.backend import get_changefeed, connect from bigchaindb.backend.changefeed import ChangeFeed conn = connect() mock_cursor_next.side_effect = [mock.DEFAULT] + mock_changefeed_data mock_cursor_find_one.return_value = mock_changefeed_data[2]['o'] outpipe = Pipe() changefeed = get_changefeed(conn, 'backlog', ChangeFeed.INSERT | ChangeFeed.UPDATE) changefeed.outqueue = outpipe changefeed.run_forever() assert outpipe.get()['msg'] == 'seems like we have an insert here' assert outpipe.get()['msg'] == 'seems like we have an update here' assert outpipe.qsize() == 0
def get_changefeed(): connection = backend.connect(**bigchaindb.config['database']) return backend.get_changefeed(connection, 'votes', ChangeFeed.INSERT)
def get_changefeed(): connection = backend.connect(**bigchaindb.config['database']) return backend.get_changefeed(connection, 'bigchain', ChangeFeed.INSERT, prefeed=initial())
def get_changefeed(): connection = backend.connect(**bigchaindb.config['database']) return backend.get_changefeed(connection, 'backlog', ChangeFeed.INSERT | ChangeFeed.UPDATE)