Fix usage of backend functions that weren't getting a connection passed in

This commit is contained in:
Brett Sun 2016-12-06 14:38:38 +01:00 committed by Sylvain Bellemare
parent 8caeed54bf
commit 32b6c50d63
3 changed files with 14 additions and 9 deletions

View File

@ -208,7 +208,7 @@ def get_last_voted_block(connection, node_pubkey):
except r.ReqlNonExistenceError:
# return last vote if last vote exists else return Genesis block
return get_genesis_block()
return get_genesis_block(connection)
# Now the fun starts. Since the resolution of timestamp is a second,
# we might have more than one vote per timestamp. If this is the case

View File

@ -21,7 +21,7 @@ def test_init_creates_db_tables_and_indexes():
# The db is set up by fixtures so we need to remove it
conn.run(r.db_drop(dbname))
schema.create_database()
schema.create_database(conn, dbname)
assert conn.run(r.db_list().contains(dbname)) is True

View File

@ -270,7 +270,8 @@ class TestBigchainApi(object):
@pytest.mark.usefixtures('inputs')
def test_genesis_block(self, b):
block = b.backend.get_genesis_block()
from bigchaindb.backend import query
block = query.get_genesis_block(b.connection)
assert len(block['block']['transactions']) == 1
assert block['block']['transactions'][0]['operation'] == 'GENESIS'
@ -286,8 +287,9 @@ class TestBigchainApi(object):
@pytest.mark.skipif(reason='This test may not make sense after changing the chainification mode')
def test_get_last_block(self, b):
from bigchaindb.backend import query
# get the number of blocks
num_blocks = b.backend.count_blocks()
num_blocks = query.count_blocks(b.connection)
# get the last block
last_block = b.get_last_block()
@ -340,9 +342,10 @@ class TestBigchainApi(object):
def test_get_last_voted_block_returns_genesis_if_no_votes_has_been_casted(self, b):
from bigchaindb.models import Block
from bigchaindb.backend import query
b.create_genesis_block()
genesis = b.backend.get_genesis_block()
genesis = query.get_genesis_block(b.connection)
genesis = Block.from_dict(genesis)
gb = b.get_last_voted_block()
assert gb == genesis
@ -477,6 +480,7 @@ class TestBigchainApi(object):
@pytest.mark.usefixtures('inputs')
def test_assign_transaction_one_node(self, b, user_pk, user_sk):
from bigchaindb.backend import query
from bigchaindb.models import Transaction
input_tx = b.get_owned_ids(user_pk).pop()
@ -487,13 +491,14 @@ class TestBigchainApi(object):
b.write_transaction(tx)
# retrieve the transaction
response = list(b.backend.get_stale_transactions(0))[0]
response = list(query.get_stale_transactions(b.connection, 0))[0]
# check if the assignee is the current node
assert response['assignee'] == b.me
@pytest.mark.usefixtures('inputs')
def test_assign_transaction_multiple_nodes(self, b, user_pk, user_sk):
from bigchaindb.backend import query
from bigchaindb.common.crypto import generate_key_pair
from bigchaindb.models import Transaction
@ -511,13 +516,12 @@ class TestBigchainApi(object):
b.write_transaction(tx)
# retrieve the transaction
response = b.backend.get_stale_transactions(0)
response = query.get_stale_transactions(b.connection, 0)
# check if the assignee is one of the _other_ federation nodes
for tx in response:
assert tx['assignee'] in b.nodes_except_me
@pytest.mark.usefixtures('inputs')
def test_non_create_input_not_found(self, b, user_pk):
from cryptoconditions import Ed25519Fulfillment
@ -537,6 +541,7 @@ class TestBigchainApi(object):
tx.validate(Bigchain())
def test_count_backlog(self, b, user_pk):
from bigchaindb.backend import query
from bigchaindb.models import Transaction
for _ in range(4):
@ -544,7 +549,7 @@ class TestBigchainApi(object):
[([user_pk], 1)]).sign([b.me_private])
b.write_transaction(tx)
assert b.backend.count_backlog() == 4
assert query.count_backlog(b.connection) == 4
class TestTransactionValidation(object):