Do not mix abci and bdb marks.

This commit is contained in:
Lev Berman 2018-09-12 13:36:19 +02:00
parent 3a0e1af3da
commit 47269fffda
2 changed files with 21 additions and 18 deletions

View File

@ -23,8 +23,10 @@ from pymongo import MongoClient
from bigchaindb.common import crypto from bigchaindb.common import crypto
from bigchaindb.log import setup_logging from bigchaindb.log import setup_logging
from bigchaindb.tendermint_utils import key_from_base64 from bigchaindb.tendermint_utils import key_from_base64
from bigchaindb.backend import schema
from bigchaindb.common.crypto import (key_pair_from_ed25519_key, from bigchaindb.common.crypto import (key_pair_from_ed25519_key,
public_key_from_ed25519_key) public_key_from_ed25519_key)
from bigchaindb.common.exceptions import DatabaseDoesNotExist
from bigchaindb.lib import Block from bigchaindb.lib import Block
@ -113,17 +115,12 @@ def _configure_bigchaindb(request):
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def _setup_database(_configure_bigchaindb): def _setup_database(_configure_bigchaindb):
from bigchaindb import config from bigchaindb import config
from bigchaindb.backend import connect, schema from bigchaindb.backend import connect
from bigchaindb.common.exceptions import DatabaseDoesNotExist
print('Initializing test db') print('Initializing test db')
dbname = config['database']['name'] dbname = config['database']['name']
conn = connect() conn = connect()
try: _drop_db(conn, dbname)
schema.drop_database(conn, dbname)
except DatabaseDoesNotExist:
pass
schema.init_database(conn) schema.init_database(conn)
print('Finishing init database') print('Finishing init database')
@ -131,10 +128,7 @@ def _setup_database(_configure_bigchaindb):
print('Deleting `{}` database'.format(dbname)) print('Deleting `{}` database'.format(dbname))
conn = connect() conn = connect()
try: _drop_db(conn, dbname)
schema.drop_database(conn, dbname)
except DatabaseDoesNotExist:
pass
print('Finished deleting `{}`'.format(dbname)) print('Finished deleting `{}`'.format(dbname))
@ -270,7 +264,6 @@ def signed_create_tx(alice, create_tx):
return create_tx.sign([alice.private_key]) return create_tx.sign([alice.private_key])
@pytest.mark.abci
@pytest.fixture @pytest.fixture
def posted_create_tx(b, signed_create_tx): def posted_create_tx(b, signed_create_tx):
res = b.post_transaction(signed_create_tx, 'broadcast_tx_commit') res = b.post_transaction(signed_create_tx, 'broadcast_tx_commit')
@ -321,8 +314,7 @@ def inputs(user_pk, b, alice):
@pytest.fixture @pytest.fixture
def dummy_db(request): def dummy_db(request):
from bigchaindb.backend import connect, schema from bigchaindb.backend import connect
from bigchaindb.common.exceptions import DatabaseDoesNotExist
conn = connect() conn = connect()
dbname = request.fixturename dbname = request.fixturename
@ -330,9 +322,14 @@ def dummy_db(request):
if xdist_suffix: if xdist_suffix:
dbname = '{}_{}'.format(dbname, xdist_suffix) dbname = '{}_{}'.format(dbname, xdist_suffix)
_drop_db(conn, dbname) # make sure we start with a clean DB
schema.init_database(conn, dbname) schema.init_database(conn, dbname)
yield dbname yield dbname
_drop_db(conn, dbname)
def _drop_db(conn, dbname):
try: try:
schema.drop_database(conn, dbname) schema.drop_database(conn, dbname)
except DatabaseDoesNotExist: except DatabaseDoesNotExist:
@ -428,7 +425,6 @@ def event_loop():
loop.close() loop.close()
@pytest.mark.bdb
@pytest.fixture(scope='session') @pytest.fixture(scope='session')
def abci_server(): def abci_server():
from abci import ABCIServer from abci import ABCIServer

View File

@ -5,11 +5,12 @@
import pytest import pytest
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
pytestmark = [pytest.mark.bdb, pytest.mark.usefixtures('inputs')]
OUTPUTS_ENDPOINT = '/api/v1/outputs/' OUTPUTS_ENDPOINT = '/api/v1/outputs/'
@pytest.mark.bdb
@pytest.mark.userfixtures('inputs')
def test_get_outputs_endpoint(client, user_pk): def test_get_outputs_endpoint(client, user_pk):
m = MagicMock() m = MagicMock()
m.txid = 'a' m.txid = 'a'
@ -38,6 +39,8 @@ def test_get_outputs_endpoint_unspent(client, user_pk):
gof.assert_called_once_with(user_pk, False) gof.assert_called_once_with(user_pk, False)
@pytest.mark.bdb
@pytest.mark.userfixtures('inputs')
def test_get_outputs_endpoint_spent(client, user_pk): def test_get_outputs_endpoint_spent(client, user_pk):
m = MagicMock() m = MagicMock()
m.txid = 'a' m.txid = 'a'
@ -51,11 +54,15 @@ def test_get_outputs_endpoint_spent(client, user_pk):
gof.assert_called_once_with(user_pk, True) gof.assert_called_once_with(user_pk, True)
@pytest.mark.bdb
@pytest.mark.userfixtures('inputs')
def test_get_outputs_endpoint_without_public_key(client): def test_get_outputs_endpoint_without_public_key(client):
res = client.get(OUTPUTS_ENDPOINT) res = client.get(OUTPUTS_ENDPOINT)
assert res.status_code == 400 assert res.status_code == 400
@pytest.mark.bdb
@pytest.mark.userfixtures('inputs')
def test_get_outputs_endpoint_with_invalid_public_key(client): def test_get_outputs_endpoint_with_invalid_public_key(client):
expected = {'message': {'public_key': 'Invalid base58 ed25519 key'}} expected = {'message': {'public_key': 'Invalid base58 ed25519 key'}}
res = client.get(OUTPUTS_ENDPOINT + '?public_key=abc') res = client.get(OUTPUTS_ENDPOINT + '?public_key=abc')
@ -63,6 +70,8 @@ def test_get_outputs_endpoint_with_invalid_public_key(client):
assert res.status_code == 400 assert res.status_code == 400
@pytest.mark.bdb
@pytest.mark.userfixtures('inputs')
def test_get_outputs_endpoint_with_invalid_spent(client, user_pk): def test_get_outputs_endpoint_with_invalid_spent(client, user_pk):
expected = {'message': {'spent': 'Boolean value must be "true" or "false" (lowercase)'}} expected = {'message': {'spent': 'Boolean value must be "true" or "false" (lowercase)'}}
params = '?spent=tru&public_key={}'.format(user_pk) params = '?spent=tru&public_key={}'.format(user_pk)
@ -72,8 +81,6 @@ def test_get_outputs_endpoint_with_invalid_spent(client, user_pk):
@pytest.mark.abci @pytest.mark.abci
@pytest.mark.bdb
@pytest.mark.usefixtures('inputs')
def test_get_divisble_transactions_returns_500(b, client): def test_get_divisble_transactions_returns_500(b, client):
from bigchaindb.models import Transaction from bigchaindb.models import Transaction
from bigchaindb.common import crypto from bigchaindb.common import crypto