Merge pull request #954 from sbellem/re-work-test-fixtures-iter-one

Re work test fixtures iter one
This commit is contained in:
Sylvain Bellemare 2016-12-16 20:59:27 +01:00 committed by GitHub
commit c81e7a7479
17 changed files with 170 additions and 236 deletions

View File

@ -1,13 +0,0 @@
import pytest
from ..db import conftest
@pytest.fixture(autouse=True)
def restore_config(request, node_config):
from bigchaindb import config_utils
config_utils.set_config(node_config)
@pytest.fixture(scope='function', autouse=True)
def setup_database(request, node_config):
conftest.setup_database(request, node_config)

View File

@ -1,8 +1,6 @@
import pytest
from unittest.mock import patch
from ..db.conftest import inputs # noqa
@pytest.mark.usefixtures('inputs')
def test_asset_transfer(b, user_pk, user_sk):

View File

@ -2,8 +2,6 @@ import pytest
from unittest.mock import patch
from ..db.conftest import inputs # noqa
# CREATE divisible asset
# Single input

View File

@ -11,7 +11,10 @@ import copy
import pytest
from bigchaindb.common import crypto
USER2_SK, USER2_PK = crypto.generate_key_pair()
DB_NAME = 'bigchain_test_{}'.format(os.getpid())
CONFIG = {
@ -45,7 +48,7 @@ def pytest_addoption(parser):
# conf file located in the home of the user running
# the tests. If it's too aggressive we can change it
# later.
@pytest.fixture(scope='function', autouse=True)
@pytest.fixture
def ignore_local_config_file(monkeypatch):
def mock_file_config(filename=None):
raise FileNotFoundError()
@ -54,8 +57,8 @@ def ignore_local_config_file(monkeypatch):
mock_file_config)
@pytest.fixture(scope='function', autouse=True)
def restore_config(request, node_config):
@pytest.fixture
def restore_config(ignore_local_config_file, node_config):
from bigchaindb import config_utils
config_utils.set_config(node_config)
@ -81,8 +84,17 @@ def user_pk():
@pytest.fixture
def b(request, node_config):
restore_config(request, node_config)
def user2_sk():
return USER2_SK
@pytest.fixture
def user2_pk():
return USER2_PK
@pytest.fixture
def b(restore_config):
from bigchaindb import Bigchain
return Bigchain()
@ -119,3 +131,90 @@ def structurally_valid_vote():
'timestamp': '1111111111'
}
}
@pytest.fixture
def setup_database(request, restore_config, node_config):
from bigchaindb.backend import connect, schema
from bigchaindb.common.exceptions import DatabaseDoesNotExist
print('Initializing test db')
db_name = node_config['database']['name']
conn = connect()
try:
schema.drop_database(conn, db_name)
except DatabaseDoesNotExist:
pass
schema.init_database(conn)
print('Finishing init database')
def fin():
conn = connect()
print('Deleting `{}` database'.format(db_name))
try:
schema.drop_database(conn, db_name)
except DatabaseDoesNotExist:
pass
print('Finished deleting `{}`'.format(db_name))
request.addfinalizer(fin)
@pytest.fixture
def inputs(user_pk, setup_database):
from bigchaindb import Bigchain
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
# 1. create the genesis block
b = Bigchain()
try:
g = b.create_genesis_block()
except GenesisBlockAlreadyExistsError:
pass
# 2. create blocks with transactions for `USER` to spend
prev_block_id = g.id
for block in range(4):
transactions = [
Transaction.create([b.me], [([user_pk], 1)]).sign([b.me_private])
for i in range(10)
]
block = b.create_block(transactions)
b.write_block(block)
# 3. vote the blocks valid, so that the inputs are valid
vote = b.vote(block.id, prev_block_id, True)
prev_block_id = block.id
b.write_vote(vote)
@pytest.fixture
def inputs_shared(user_pk, user2_pk, setup_database):
from bigchaindb import Bigchain
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
# 1. create the genesis block
b = Bigchain()
try:
g = b.create_genesis_block()
except GenesisBlockAlreadyExistsError:
pass
# 2. create blocks with transactions for `USER` to spend
prev_block_id = g.id
for block in range(4):
transactions = [
Transaction.create(
[b.me], [user_pk, user2_pk], payload={'i': i}).sign([b.me_private])
for i in range(10)
]
block = b.create_block(transactions)
b.write_block(block)
# 3. vote the blocks valid, so that the inputs are valid
vote = b.vote(block.id, prev_block_id, True)
prev_block_id = block.id
b.write_vote(vote)

View File

@ -1,116 +0,0 @@
"""
Fixtures and setup / teardown functions
Tasks:
1. setup test database before starting the tests
2. delete test database after running the tests
"""
import pytest
from bigchaindb import Bigchain
from bigchaindb.backend import connect, schema
from bigchaindb.common import crypto
from bigchaindb.common.exceptions import DatabaseDoesNotExist
USER2_SK, USER2_PK = crypto.generate_key_pair()
@pytest.fixture(autouse=True)
def restore_config(request, node_config):
from bigchaindb import config_utils
config_utils.set_config(node_config)
@pytest.fixture(scope='function', autouse=True)
def setup_database(request, node_config):
print('Initializing test db')
db_name = node_config['database']['name']
conn = connect()
try:
schema.drop_database(conn, db_name)
except DatabaseDoesNotExist:
pass
schema.init_database(conn)
print('Finishing init database')
def fin():
conn = connect()
print('Deleting `{}` database'.format(db_name))
try:
schema.drop_database(conn, db_name)
except DatabaseDoesNotExist:
pass
print('Finished deleting `{}`'.format(db_name))
request.addfinalizer(fin)
@pytest.fixture
def inputs(user_pk):
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
# 1. create the genesis block
b = Bigchain()
try:
g = b.create_genesis_block()
except GenesisBlockAlreadyExistsError:
pass
# 2. create blocks with transactions for `USER` to spend
prev_block_id = g.id
for block in range(4):
transactions = [
Transaction.create([b.me], [([user_pk], 1)]).sign([b.me_private])
for i in range(10)
]
block = b.create_block(transactions)
b.write_block(block)
# 3. vote the blocks valid, so that the inputs are valid
vote = b.vote(block.id, prev_block_id, True)
prev_block_id = block.id
b.write_vote(vote)
@pytest.fixture
def user2_sk():
return USER2_SK
@pytest.fixture
def user2_pk():
return USER2_PK
@pytest.fixture
def inputs_shared(user_pk, user2_pk):
from bigchaindb.models import Transaction
from bigchaindb.common.exceptions import GenesisBlockAlreadyExistsError
# 1. create the genesis block
b = Bigchain()
try:
g = b.create_genesis_block()
except GenesisBlockAlreadyExistsError:
pass
# 2. create blocks with transactions for `USER` to spend
prev_block_id = g.id
for block in range(4):
transactions = [
Transaction.create(
[b.me], [user_pk, user2_pk], payload={'i': i}).sign([b.me_private])
for i in range(10)
]
block = b.create_block(transactions)
b.write_block(block)
# 3. vote the blocks valid, so that the inputs are valid
vote = b.vote(block.id, prev_block_id, True)
prev_block_id = block.id
b.write_vote(vote)

View File

@ -4,16 +4,9 @@ import rethinkdb as r
import bigchaindb
from bigchaindb import backend
from bigchaindb.backend.rethinkdb import schema
from ..conftest import setup_database as _setup_database
# Since we are testing database initialization and database drop,
# we need to use the `setup_database` fixture on a function level
@pytest.fixture(scope='function', autouse=True)
def setup_database(request, node_config):
_setup_database(request, node_config)
@pytest.mark.usefixtures('setup_database')
def test_init_creates_db_tables_and_indexes():
from bigchaindb.backend.schema import init_database
conn = backend.connect()
@ -35,6 +28,7 @@ def test_init_creates_db_tables_and_indexes():
'assignee__transaction_timestamp')) is True
@pytest.mark.usefixtures('setup_database')
def test_init_database_fails_if_db_exists():
from bigchaindb.backend.schema import init_database
from bigchaindb.common import exceptions
@ -52,14 +46,11 @@ def test_init_database_fails_if_db_exists():
def test_create_database():
conn = backend.connect()
dbname = bigchaindb.config['database']['name']
# The db is set up by fixtures so we need to remove it
# and recreate it just with one table
conn.run(r.db_drop(dbname))
schema.create_database(conn, dbname)
assert conn.run(r.db_list().contains(dbname)) is True
@pytest.mark.usefixtures('setup_database')
def test_create_tables():
conn = backend.connect()
dbname = bigchaindb.config['database']['name']
@ -76,6 +67,7 @@ def test_create_tables():
assert len(conn.run(r.db(dbname).table_list())) == 3
@pytest.mark.usefixtures('setup_database')
def test_create_secondary_indexes():
conn = backend.connect()
dbname = bigchaindb.config['database']['name']
@ -104,6 +96,7 @@ def test_create_secondary_indexes():
'block_and_voter')) is True
@pytest.mark.usefixtures('setup_database')
def test_drop():
conn = backend.connect()
dbname = bigchaindb.config['database']['name']
@ -115,6 +108,7 @@ def test_drop():
assert conn.run(r.db_list().contains(dbname)) is False
@pytest.mark.usefixtures('setup_database')
def test_drop_non_existent_db_raises_an_error():
from bigchaindb.common import exceptions

View File

@ -28,6 +28,7 @@ def dummy_block():
return block
@pytest.mark.usefixtures('setup_database')
class TestBigchainApi(object):
def test_get_last_voted_block_cyclic_blockchain(self, b, monkeypatch):
from bigchaindb.common.crypto import PrivateKey
@ -571,6 +572,7 @@ class TestTransactionValidation(object):
assert excinfo.value.args[0] == 'Only `CREATE` transactions can have null inputs'
@pytest.mark.usefixtures('setup_database')
def test_non_create_input_not_found(self, b, user_pk, signed_transfer_tx):
from bigchaindb.common.exceptions import TransactionDoesNotExist
from bigchaindb.common.transaction import TransactionLink
@ -721,6 +723,7 @@ class TestBlockValidation(object):
assert excinfo.value.args[0] == 'owner_before `a` does not own the input `{}`'.format(valid_input)
@pytest.mark.usefixtures('setup_database')
def test_invalid_signature(self, b):
from bigchaindb.common.exceptions import InvalidSignature
from bigchaindb.common import crypto
@ -735,6 +738,7 @@ class TestBlockValidation(object):
with pytest.raises(InvalidSignature):
b.validate_block(block)
@pytest.mark.usefixtures('setup_database')
def test_invalid_node_pubkey(self, b):
from bigchaindb.common.exceptions import OperationError
from bigchaindb.common import crypto
@ -861,6 +865,7 @@ class TestMultipleInputs(object):
assert len(tx.fulfillments) == 1
assert len(tx.conditions) == 1
@pytest.mark.usefixtures('setup_database')
def test_get_owned_ids_single_tx_single_output(self, b, user_sk, user_pk):
from bigchaindb.common import crypto
from bigchaindb.common.transaction import TransactionLink
@ -888,6 +893,7 @@ class TestMultipleInputs(object):
assert owned_inputs_user1 == []
assert owned_inputs_user2 == [TransactionLink(tx.id, 0)]
@pytest.mark.usefixtures('setup_database')
def test_get_owned_ids_single_tx_single_output_invalid_block(self, b,
user_sk,
user_pk):
@ -931,6 +937,7 @@ class TestMultipleInputs(object):
assert owned_inputs_user1 == [TransactionLink(tx.id, 0)]
assert owned_inputs_user2 == []
@pytest.mark.usefixtures('setup_database')
def test_get_owned_ids_single_tx_multiple_outputs(self, b, user_sk,
user_pk):
from bigchaindb.common import crypto
@ -971,6 +978,7 @@ class TestMultipleInputs(object):
assert owned_inputs_user2 == [TransactionLink(tx_transfer.id, 0),
TransactionLink(tx_transfer.id, 1)]
@pytest.mark.usefixtures('setup_database')
def test_get_owned_ids_multiple_owners(self, b, user_sk, user_pk):
from bigchaindb.common import crypto
from bigchaindb.common.transaction import TransactionLink
@ -1001,6 +1009,7 @@ class TestMultipleInputs(object):
assert owned_inputs_user1 == owned_inputs_user2
assert owned_inputs_user1 == []
@pytest.mark.usefixtures('setup_database')
def test_get_spent_single_tx_single_output(self, b, user_sk, user_pk):
from bigchaindb.common import crypto
from bigchaindb.models import Transaction
@ -1029,6 +1038,7 @@ class TestMultipleInputs(object):
spent_inputs_user1 = b.get_spent(input_txid, input_cid)
assert spent_inputs_user1 == tx
@pytest.mark.usefixtures('setup_database')
def test_get_spent_single_tx_single_output_invalid_block(self, b, user_sk, user_pk):
from bigchaindb.common import crypto
from bigchaindb.models import Transaction
@ -1071,6 +1081,7 @@ class TestMultipleInputs(object):
# Now there should be no spents (the block is invalid)
assert spent_inputs_user1 is None
@pytest.mark.usefixtures('setup_database')
def test_get_spent_single_tx_multiple_outputs(self, b, user_sk, user_pk):
from bigchaindb.common import crypto
from bigchaindb.models import Transaction
@ -1113,6 +1124,7 @@ class TestMultipleInputs(object):
# spendable by BigchainDB
assert b.get_spent(tx_create.to_inputs()[2].tx_input.txid, 2) is None
@pytest.mark.usefixtures('setup_database')
def test_get_spent_multiple_owners(self, b, user_sk, user_pk):
import random
from bigchaindb.common import crypto

View File

@ -1,23 +1,9 @@
import pytest
from bigchaindb.pipelines import block, election, vote, stale
# TODO: fix this import madness
from ..db import conftest
@pytest.fixture(scope='module', autouse=True)
def restore_config(request, node_config):
from bigchaindb import config_utils
config_utils.set_config(node_config)
@pytest.fixture(scope='function', autouse=True)
def setup_database(request, node_config):
conftest.setup_database(request, node_config)
@pytest.fixture
def processes(b):
def processes(b, setup_database):
b.create_genesis_block()
block_maker = block.start()
voter = vote.start()

View File

@ -1,35 +1,14 @@
import time
import pytest
from bigchaindb import Bigchain
@pytest.fixture
def inputs(user_pk):
from bigchaindb.models import Transaction
b = Bigchain()
# create blocks with transactions for `USER` to spend
for block in range(4):
transactions = [
Transaction.create(
[b.me], [([user_pk], 1)],
metadata={'i': i})
.sign([b.me_private])
for i in range(10)
]
block = b.create_block(transactions)
b.write_block(block, durability='hard')
@pytest.mark.usefixtures('processes')
def test_fast_double_create(b, user_pk):
from bigchaindb.models import Transaction
from bigchaindb.backend.query import count_blocks
tx = Transaction.create([b.me], [([user_pk], 1)],
metadata={'test': 'test'}) \
.sign([b.me_private])
metadata={'test': 'test'}).sign([b.me_private])
# write everything fast
b.write_transaction(tx)
@ -51,8 +30,7 @@ def test_double_create(b, user_pk):
from bigchaindb.models import Transaction
from bigchaindb.backend.query import count_blocks
tx = Transaction.create([b.me], [([user_pk], 1)],
metadata={'test': 'test'}) \
.sign([b.me_private])
metadata={'test': 'test'}).sign([b.me_private])
b.write_transaction(tx)
time.sleep(2)

View File

@ -1,13 +0,0 @@
import pytest
from ..db import conftest
@pytest.fixture(autouse=True)
def restore_config(request, node_config):
from bigchaindb import config_utils
config_utils.set_config(node_config)
@pytest.fixture(scope='function', autouse=True)
def setup_database(request, node_config):
conftest.setup_database(request, node_config)

View File

@ -2,6 +2,7 @@ import time
from unittest.mock import patch
from multipipes import Pipe
import pytest
def test_filter_by_assignee(b, signed_create_tx):
@ -25,6 +26,7 @@ def test_filter_by_assignee(b, signed_create_tx):
assert block_maker.filter_tx(tx) is None
@pytest.mark.usefixtures('setup_database')
def test_validate_transaction(b, create_tx):
from bigchaindb.pipelines.block import BlockPipeline
@ -53,6 +55,7 @@ def test_create_block(b, user_pk):
assert len(block_doc.transactions) == 100
@pytest.mark.usefixtures('setup_database')
def test_write_block(b, user_pk):
from bigchaindb.models import Block, Transaction
from bigchaindb.pipelines.block import BlockPipeline
@ -73,6 +76,7 @@ def test_write_block(b, user_pk):
assert expected == block_doc
@pytest.mark.usefixtures('setup_database')
def test_duplicate_transaction(b, user_pk):
from bigchaindb.models import Transaction
from bigchaindb.pipelines import block
@ -104,6 +108,7 @@ def test_duplicate_transaction(b, user_pk):
assert status != b.TX_IN_BACKLOG
@pytest.mark.usefixtures('setup_database')
def test_delete_tx(b, user_pk):
from bigchaindb.models import Transaction
from bigchaindb.pipelines.block import BlockPipeline
@ -132,6 +137,7 @@ def test_delete_tx(b, user_pk):
@patch('bigchaindb.pipelines.block.create_pipeline')
@pytest.mark.usefixtures('setup_database')
def test_start(create_pipeline):
from bigchaindb.pipelines import block
@ -142,6 +148,7 @@ def test_start(create_pipeline):
assert pipeline == create_pipeline.return_value
@pytest.mark.usefixtures('setup_database')
def test_full_pipeline(b, user_pk):
import random
from bigchaindb.backend import query

View File

@ -1,6 +1,8 @@
import time
from unittest.mock import patch
import pytest
from bigchaindb.common import crypto
from multipipes import Pipe, Pipeline
@ -8,6 +10,7 @@ from bigchaindb import Bigchain
from bigchaindb.pipelines import election
@pytest.mark.usefixtures('setup_database')
def test_check_for_quorum_invalid(b, user_pk):
from bigchaindb.models import Transaction
@ -41,6 +44,7 @@ def test_check_for_quorum_invalid(b, user_pk):
assert e.check_for_quorum(votes[-1]) == test_block
@pytest.mark.usefixtures('setup_database')
def test_check_for_quorum_invalid_prev_node(b, user_pk):
from bigchaindb.models import Transaction
e = election.Election()
@ -75,6 +79,7 @@ def test_check_for_quorum_invalid_prev_node(b, user_pk):
assert e.check_for_quorum(votes[-1]) == test_block
@pytest.mark.usefixtures('setup_database')
def test_check_for_quorum_valid(b, user_pk):
from bigchaindb.models import Transaction
@ -107,6 +112,7 @@ def test_check_for_quorum_valid(b, user_pk):
assert e.check_for_quorum(votes[-1]) is None
@pytest.mark.usefixtures('setup_database')
def test_check_requeue_transaction(b, user_pk):
from bigchaindb.models import Transaction
@ -134,6 +140,7 @@ def test_start(mock_start):
mock_start.assert_called_with()
@pytest.mark.usefixtures('setup_database')
def test_full_pipeline(b, user_pk):
import random
from bigchaindb.backend import query

View File

@ -5,7 +5,10 @@ from unittest.mock import patch
from bigchaindb import config_utils
import os
import pytest
@pytest.mark.usefixtures('setup_database')
def test_get_stale(b, user_pk):
from bigchaindb.models import Transaction
tx = Transaction.create([b.me], [([user_pk], 1)])
@ -22,6 +25,7 @@ def test_get_stale(b, user_pk):
assert tx.to_dict() == _tx
@pytest.mark.usefixtures('setup_database')
def test_reassign_transactions(b, user_pk):
from bigchaindb.backend import query
from bigchaindb.models import Transaction
@ -61,6 +65,7 @@ def test_reassign_transactions(b, user_pk):
assert tx['assignee'] != 'lol'
@pytest.mark.usefixtures('setup_database')
def test_full_pipeline(monkeypatch, user_pk):
from bigchaindb.backend import query
from bigchaindb.models import Transaction

View File

@ -1,8 +1,8 @@
import time
from unittest.mock import patch
from multipipes import Pipe, Pipeline
import pytest
def dummy_tx(b):
@ -59,6 +59,7 @@ def test_vote_creation_invalid(b):
vote['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_vote_ungroup_returns_a_set_of_results(b):
from bigchaindb.pipelines import vote
@ -70,6 +71,7 @@ def test_vote_ungroup_returns_a_set_of_results(b):
assert len(txs) == 10
@pytest.mark.usefixtures('setup_database')
def test_vote_validate_block(b):
from bigchaindb.pipelines import vote
@ -94,6 +96,7 @@ def test_vote_validate_block(b):
assert tx1 == tx2
@pytest.mark.usefixtures('setup_database')
def test_validate_block_with_invalid_id(b):
from bigchaindb.pipelines import vote
@ -108,6 +111,7 @@ def test_validate_block_with_invalid_id(b):
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
@pytest.mark.usefixtures('setup_database')
def test_validate_block_with_invalid_signature(b):
from bigchaindb.pipelines import vote
@ -122,6 +126,7 @@ def test_validate_block_with_invalid_signature(b):
assert invalid_dummy_tx == [vote_obj.invalid_dummy_tx]
@pytest.mark.usefixtures('setup_database')
def test_vote_validate_transaction(b):
from bigchaindb.pipelines import vote
from bigchaindb.models import Transaction
@ -138,6 +143,7 @@ def test_vote_validate_transaction(b):
assert validation == (False, 456, 10)
@pytest.mark.usefixtures('setup_database')
def test_vote_accumulates_transactions(b):
from bigchaindb.pipelines import vote
@ -156,6 +162,7 @@ def test_vote_accumulates_transactions(b):
assert validation == (False, 456, 10)
@pytest.mark.usefixtures('setup_database')
def test_valid_block_voting_sequential(b, monkeypatch):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
@ -185,6 +192,7 @@ def test_valid_block_voting_sequential(b, monkeypatch):
vote_doc['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_valid_block_voting_multiprocessing(b, monkeypatch):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
@ -220,6 +228,7 @@ def test_valid_block_voting_multiprocessing(b, monkeypatch):
vote_doc['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_valid_block_voting_with_create_transaction(b, monkeypatch):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
@ -262,6 +271,7 @@ def test_valid_block_voting_with_create_transaction(b, monkeypatch):
vote_doc['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
@ -332,6 +342,7 @@ def test_valid_block_voting_with_transfer_transactions(monkeypatch, b):
vote2_doc['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
@ -370,6 +381,7 @@ def test_unsigned_tx_in_block_voting(monkeypatch, b, user_pk):
vote_doc['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
@ -410,6 +422,7 @@ def test_invalid_id_tx_in_block_voting(monkeypatch, b, user_pk):
vote_doc['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
@ -450,6 +463,7 @@ def test_invalid_content_in_tx_in_block_voting(monkeypatch, b, user_pk):
vote_doc['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_invalid_block_voting(monkeypatch, b, user_pk):
from bigchaindb.backend import query
from bigchaindb.common import crypto, util
@ -486,6 +500,7 @@ def test_invalid_block_voting(monkeypatch, b, user_pk):
vote_doc['signature']) is True
@pytest.mark.usefixtures('setup_database')
def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b):
from bigchaindb.backend import query
from bigchaindb.pipelines import vote
@ -534,6 +549,7 @@ def test_voter_considers_unvoted_blocks_when_single_node(monkeypatch, b):
assert all(vote['node_pubkey'] == b.me for vote in votes)
@pytest.mark.usefixtures('setup_database')
def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b):
from bigchaindb.backend import query
from bigchaindb.pipelines import vote
@ -575,6 +591,7 @@ def test_voter_chains_blocks_with_the_previous_ones(monkeypatch, b):
{block['id'] for block in blocks})
@pytest.mark.usefixtures('setup_database')
def test_voter_checks_for_previous_vote(monkeypatch, b):
from bigchaindb.backend import query
from bigchaindb.pipelines import vote
@ -616,6 +633,7 @@ def test_voter_checks_for_previous_vote(monkeypatch, b):
@patch.object(Pipeline, 'start')
@pytest.mark.usefixtures('setup_database')
def test_start(mock_start, b):
# TODO: `block.start` is just a wrapper around `vote.create_pipeline`,
# that is tested by `test_full_pipeline`.

View File

@ -21,13 +21,8 @@ def mock_write_config(monkeypatch):
@pytest.fixture
def mock_db_init_with_existing_db(monkeypatch):
from bigchaindb import commands
from bigchaindb.common.exceptions import DatabaseAlreadyExists
def mockreturn():
raise DatabaseAlreadyExists
monkeypatch.setattr(commands.bigchain, '_run_init', mockreturn)
from bigchaindb.commands import bigchain
monkeypatch.setattr(bigchain, '_run_init', lambda: None)
@pytest.fixture
@ -305,6 +300,7 @@ def test_start_rethinkdb_exits_when_cannot_start(mock_popen):
@patch('bigchaindb.common.crypto.generate_key_pair',
return_value=('private_key', 'public_key'))
@pytest.mark.usefixtures('restore_config')
def test_allow_temp_keypair_generates_one_on_the_fly(mock_gen_keypair,
mock_processes_start,
mock_db_init_with_existing_db):
@ -322,6 +318,7 @@ def test_allow_temp_keypair_generates_one_on_the_fly(mock_gen_keypair,
@patch('bigchaindb.common.crypto.generate_key_pair',
return_value=('private_key', 'public_key'))
@pytest.mark.usefixtures('restore_config')
def test_allow_temp_keypair_doesnt_override_if_keypair_found(mock_gen_keypair,
mock_processes_start,
mock_db_init_with_existing_db):

View File

@ -1,32 +1,8 @@
import pytest
from ..db import conftest
@pytest.fixture(autouse=True)
def restore_config(request, node_config):
from bigchaindb import config_utils
config_utils.set_config(node_config)
@pytest.fixture(scope='function', autouse=True)
def setup_database(request, node_config):
conftest.setup_database(request, node_config)
@pytest.fixture
def app(request, node_config):
# XXX: For whatever reason this fixture runs before `restore_config`,
# so we need to manually call it.
restore_config(request, node_config)
def app(request, restore_config):
from bigchaindb.web import server
app = server.create_app(debug=True)
return app
@pytest.fixture
# NOTE: In order to have a database setup as well as the `input` fixture,
# we have to proxy `db.conftest.input` here.
# TODO: If possible replace this function with something nicer.
def inputs(user_pk):
conftest.inputs(user_pk)

View File

@ -26,6 +26,7 @@ def test_get_transaction_returns_404_if_not_found(client):
assert res.status_code == 404
@pytest.mark.usefixtures('setup_database')
def test_post_create_transaction_endpoint(b, client):
from bigchaindb.models import Transaction
user_priv, user_pub = crypto.generate_key_pair()