From 9a7e695e18ac2215593d6777a1d0ff8d44dbe024 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Tue, 6 Dec 2016 15:08:19 +0100 Subject: [PATCH] Fix tests still relying on being able to access removed attribute of the Bigchain class --- tests/pipelines/test_block_creation.py | 11 ++++---- tests/pipelines/test_election.py | 5 ++-- tests/pipelines/test_stale_monitor.py | 15 ++++++---- tests/pipelines/test_vote.py | 39 +++++++++++++++++--------- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/tests/pipelines/test_block_creation.py b/tests/pipelines/test_block_creation.py index 9cc7b56c..0616365d 100644 --- a/tests/pipelines/test_block_creation.py +++ b/tests/pipelines/test_block_creation.py @@ -67,7 +67,7 @@ def test_write_block(b, user_pk): block_doc = b.create_block(txs) block_maker.write(block_doc) - expected = b.backend.get_block(block_doc.id) + expected = b.get_block(block_doc.id) expected = Block.from_dict(expected) assert expected == block_doc @@ -88,7 +88,7 @@ def test_duplicate_transaction(b, user_pk): block_maker.write(block_doc) # block is in bigchain - assert b.backend.get_block(block_doc.id) == block_doc.to_dict() + assert b.get_block(block_doc.id) == block_doc.to_dict() b.write_transaction(txs[0]) @@ -159,6 +159,7 @@ def test_start(create_pipeline): def test_full_pipeline(b, user_pk): import random + from bigchaindb.backend import query from bigchaindb.models import Block, Transaction from bigchaindb.pipelines.block import create_pipeline, get_changefeed @@ -172,7 +173,7 @@ def test_full_pipeline(b, user_pk): b.write_transaction(tx) - assert b.backend.count_backlog() == 100 + assert query.count_backlog(b.connection) == 100 pipeline = create_pipeline() pipeline.setup(indata=get_changefeed(), outdata=outpipe) @@ -182,9 +183,9 @@ def test_full_pipeline(b, user_pk): pipeline.terminate() block_doc = outpipe.get() - chained_block = b.backend.get_block(block_doc.id) + chained_block = b.get_block(block_doc.id) chained_block = Block.from_dict(chained_block) block_len = len(block_doc.transactions) assert chained_block == block_doc - assert b.backend.count_backlog() == 100 - block_len + assert query.count_backlog(b.connection) == 100 - block_len diff --git a/tests/pipelines/test_election.py b/tests/pipelines/test_election.py index 300dee3f..f9fee0bb 100644 --- a/tests/pipelines/test_election.py +++ b/tests/pipelines/test_election.py @@ -136,6 +136,7 @@ def test_start(mock_start): def test_full_pipeline(b, user_pk): import random + from bigchaindb.backend import query from bigchaindb.models import Transaction outpipe = Pipe() @@ -177,8 +178,8 @@ def test_full_pipeline(b, user_pk): # only transactions from the invalid block should be returned to # the backlog - assert b.backend.count_backlog() == 100 + assert query.count_backlog(b.connection) == 100 # NOTE: I'm still, I'm still tx from the block. tx_from_block = set([tx.id for tx in invalid_block.transactions]) - tx_from_backlog = set([tx['id'] for tx in list(b.backend.get_stale_transactions(0))]) + tx_from_backlog = set([tx['id'] for tx in list(query.get_stale_transactions(b.connection, 0))]) assert tx_from_block == tx_from_backlog diff --git a/tests/pipelines/test_stale_monitor.py b/tests/pipelines/test_stale_monitor.py index 31848122..47705889 100644 --- a/tests/pipelines/test_stale_monitor.py +++ b/tests/pipelines/test_stale_monitor.py @@ -23,6 +23,7 @@ def test_get_stale(b, user_pk): def test_reassign_transactions(b, user_pk): + from bigchaindb.backend import query from bigchaindb.models import Transaction # test with single node tx = Transaction.create([b.me], [([user_pk], 1)]) @@ -41,10 +42,10 @@ def test_reassign_transactions(b, user_pk): stm = stale.StaleTransactionMonitor(timeout=0.001, backlog_reassign_delay=0.001) stm.bigchain.nodes_except_me = ['aaa', 'bbb', 'ccc'] - tx = list(b.backend.get_stale_transactions(0))[0] + tx = list(query.get_stale_transactions(b.connection, 0))[0] stm.reassign_transactions(tx) - reassigned_tx = list(b.backend.get_stale_transactions(0))[0] + reassigned_tx = list(query.get_stale_transactions(b.connection, 0))[0] assert reassigned_tx['assignment_timestamp'] > tx['assignment_timestamp'] assert reassigned_tx['assignee'] != tx['assignee'] @@ -55,12 +56,13 @@ def test_reassign_transactions(b, user_pk): b.write_transaction(tx, durability='hard') stm.bigchain.nodes_except_me = None - tx = list(b.backend.get_stale_transactions(0))[0] + tx = list(query.get_stale_transactions(b.connection, 0))[0] stm.reassign_transactions(tx) assert tx['assignee'] != 'lol' def test_full_pipeline(monkeypatch, user_pk): + from bigchaindb.backend import query from bigchaindb.models import Transaction CONFIG = { 'database': { @@ -87,7 +89,7 @@ def test_full_pipeline(monkeypatch, user_pk): original_txc.append(tx.to_dict()) b.write_transaction(tx) - original_txs = list(b.backend.get_stale_transactions(0)) + original_txs = list(query.get_stale_transactions(b.connection, 0)) original_txs = {tx['id']: tx for tx in original_txs} assert len(original_txs) == 100 @@ -111,14 +113,15 @@ def test_full_pipeline(monkeypatch, user_pk): pipeline.terminate() - assert len(list(b.backend.get_stale_transactions(0))) == 100 - reassigned_txs= list(b.backend.get_stale_transactions(0)) + assert len(list(query.get_stale_transactions(b.connection, 0))) == 100 + reassigned_txs = list(query.get_stale_transactions(b.connection, 0)) # check that every assignment timestamp has increased, and every tx has a new assignee for reassigned_tx in reassigned_txs: assert reassigned_tx['assignment_timestamp'] > original_txs[reassigned_tx['id']]['assignment_timestamp'] assert reassigned_tx['assignee'] != original_txs[reassigned_tx['id']]['assignee'] + @patch.object(Pipeline, 'start') def test_start(mock_start): # TODO: `sta,e.start` is just a wrapper around `block.create_pipeline`, diff --git a/tests/pipelines/test_vote.py b/tests/pipelines/test_vote.py index be3652b2..3e737424 100644 --- a/tests/pipelines/test_vote.py +++ b/tests/pipelines/test_vote.py @@ -157,6 +157,7 @@ def test_vote_accumulates_transactions(b): def test_valid_block_voting_sequential(b, monkeypatch): + from bigchaindb.backend import query from bigchaindb.common import crypto, util from bigchaindb.pipelines import vote @@ -169,7 +170,7 @@ def test_valid_block_voting_sequential(b, monkeypatch): last_vote = vote_obj.vote(*vote_obj.validate_tx(tx, block_id, num_tx)) vote_obj.write_vote(last_vote) - vote_rs = b.backend.get_votes_by_block_id_and_voter(block_id, b.me) + vote_rs = query.get_votes_by_block_id_and_voter(b.connection, block_id, b.me) vote_doc = vote_rs.next() assert vote_doc['vote'] == {'voting_for_block': block.id, @@ -185,6 +186,7 @@ def test_valid_block_voting_sequential(b, monkeypatch): def test_valid_block_voting_multiprocessing(b, monkeypatch): + from bigchaindb.backend import query from bigchaindb.common import crypto, util from bigchaindb.pipelines import vote @@ -203,7 +205,7 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch): vote_out = outpipe.get() vote_pipeline.terminate() - vote_rs = b.backend.get_votes_by_block_id_and_voter(block.id, b.me) + vote_rs = query.get_votes_by_block_id_and_voter(b.connection, block.id, b.me) vote_doc = vote_rs.next() assert vote_out['vote'] == vote_doc['vote'] assert vote_doc['vote'] == {'voting_for_block': block.id, @@ -219,6 +221,7 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch): def test_valid_block_voting_with_create_transaction(b, monkeypatch): + from bigchaindb.backend import query from bigchaindb.common import crypto, util from bigchaindb.models import Transaction from bigchaindb.pipelines import vote @@ -244,7 +247,7 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch): vote_out = outpipe.get() vote_pipeline.terminate() - vote_rs = b.backend.get_votes_by_block_id_and_voter(block.id, b.me) + vote_rs = query.get_votes_by_block_id_and_voter(b.connection, block.id, b.me) vote_doc = vote_rs.next() assert vote_out['vote'] == vote_doc['vote'] assert vote_doc['vote'] == {'voting_for_block': block.id, @@ -260,6 +263,7 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch): def test_valid_block_voting_with_transfer_transactions(monkeypatch, b): + from bigchaindb.backend import query from bigchaindb.common import crypto, util from bigchaindb.models import Transaction from bigchaindb.pipelines import vote @@ -299,7 +303,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b): vote2_out = outpipe.get() vote_pipeline.terminate() - vote_rs = b.backend.get_votes_by_block_id_and_voter(block.id, b.me) + vote_rs = query.get_votes_by_block_id_and_voter(b.connection, block.id, b.me) vote_doc = vote_rs.next() assert vote_out['vote'] == vote_doc['vote'] assert vote_doc['vote'] == {'voting_for_block': block.id, @@ -313,7 +317,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b): assert crypto.PublicKey(b.me).verify(serialized_vote, vote_doc['signature']) is True - vote2_rs = b.backend.get_votes_by_block_id_and_voter(block2.id, b.me) + vote2_rs = query.get_votes_by_block_id_and_voter(b.connection, block2.id, b.me) vote2_doc = vote2_rs.next() assert vote2_out['vote'] == vote2_doc['vote'] assert vote2_doc['vote'] == {'voting_for_block': block2.id, @@ -329,6 +333,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b): def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk): + from bigchaindb.backend import query from bigchaindb.common import crypto, util from bigchaindb.models import Transaction from bigchaindb.pipelines import vote @@ -350,7 +355,7 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk): vote_out = outpipe.get() vote_pipeline.terminate() - vote_rs = b.backend.get_votes_by_block_id_and_voter(block.id, b.me) + vote_rs = query.get_votes_by_block_id_and_voter(b.connection, block.id, b.me) vote_doc = vote_rs.next() assert vote_out['vote'] == vote_doc['vote'] assert vote_doc['vote'] == {'voting_for_block': block.id, @@ -366,6 +371,7 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk): def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk): + from bigchaindb.backend import query from bigchaindb.common import crypto, util from bigchaindb.models import Transaction from bigchaindb.pipelines import vote @@ -389,7 +395,7 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk): vote_out = outpipe.get() vote_pipeline.terminate() - vote_rs = b.backend.get_votes_by_block_id_and_voter(block['id'], b.me) + vote_rs = query.get_votes_by_block_id_and_voter(b.connection, block['id'], b.me) vote_doc = vote_rs.next() assert vote_out['vote'] == vote_doc['vote'] assert vote_doc['vote'] == {'voting_for_block': block['id'], @@ -405,6 +411,7 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk): def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk): + from bigchaindb.backend import query from bigchaindb.common import crypto, util from bigchaindb.models import Transaction from bigchaindb.pipelines import vote @@ -428,7 +435,7 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk): vote_out = outpipe.get() vote_pipeline.terminate() - vote_rs = b.backend.get_votes_by_block_id_and_voter(block['id'], b.me) + vote_rs = query.get_votes_by_block_id_and_voter(b.connection, block['id'], b.me) vote_doc = vote_rs.next() assert vote_out['vote'] == vote_doc['vote'] assert vote_doc['vote'] == {'voting_for_block': block['id'], @@ -444,6 +451,7 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk): def test_invalid_block_voting(monkeypatch, b, user_pk): + from bigchaindb.backend import query from bigchaindb.common import crypto, util from bigchaindb.pipelines import vote @@ -463,7 +471,7 @@ def test_invalid_block_voting(monkeypatch, b, user_pk): vote_out = outpipe.get() vote_pipeline.terminate() - vote_rs = b.backend.get_votes_by_block_id_and_voter(block['id'], b.me) + vote_rs = query.get_votes_by_block_id_and_voter(b.connection, block['id'], b.me) vote_doc = vote_rs.next() assert vote_out['vote'] == vote_doc['vote'] assert vote_doc['vote'] == {'voting_for_block': block['id'], @@ -479,6 +487,7 @@ def test_invalid_block_voting(monkeypatch, b, user_pk): def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b): + from bigchaindb.backend import query from bigchaindb.pipelines import vote outpipe = Pipe() @@ -519,13 +528,14 @@ def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b): vote_pipeline.terminate() # retrieve vote - votes = [list(b.backend.get_votes_by_block_id(_id))[0] + votes = [list(query.get_votes_by_block_id(b.connection, _id))[0] for _id in block_ids] assert all(vote['node_pubkey'] == b.me for vote in votes) def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b): + from bigchaindb.backend import query from bigchaindb.pipelines import vote outpipe = Pipe() @@ -558,7 +568,7 @@ def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b): blocks = [b.get_block(_id) for _id in block_ids] # retrieve votes - votes = [list(b.backend.get_votes_by_block_id(_id))[0] + votes = [list(query.get_votes_by_block_id(b.connection, _id))[0] for _id in block_ids] assert ({v['vote']['voting_for_block'] for v in votes} == @@ -566,6 +576,7 @@ def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b): def test_voter_checks_for_previous_vote(monkeypatch, b): + from bigchaindb.backend import query from bigchaindb.pipelines import vote inpipe = Pipe() @@ -577,7 +588,7 @@ def test_voter_checks_for_previous_vote(monkeypatch, b): monkeypatch.setattr('time.time', lambda: 2222222222) block_1 = dummy_block(b) inpipe.put(block_1.to_dict()) - assert len(list(b.backend.get_votes_by_block_id(block_1.id))) == 0 + assert len(list(query.get_votes_by_block_id(b.connection, block_1.id))) == 0 vote_pipeline = vote.create_pipeline() vote_pipeline.setup(indata=inpipe, outdata=outpipe) @@ -600,8 +611,8 @@ def test_voter_checks_for_previous_vote(monkeypatch, b): vote_pipeline.terminate() - assert len(list(b.backend.get_votes_by_block_id(block_1.id))) == 1 - assert len(list(b.backend.get_votes_by_block_id(block_2.id))) == 1 + assert len(list(query.get_votes_by_block_id(b.connection, block_1.id))) == 1 + assert len(list(query.get_votes_by_block_id(b.connection, block_2.id))) == 1 @patch.object(Pipeline, 'start')