From 47269fffda2b77f3f176ae4a046dcf2bf0391770 Mon Sep 17 00:00:00 2001 From: Lev Berman Date: Wed, 12 Sep 2018 13:36:19 +0200 Subject: [PATCH] Do not mix abci and bdb marks. --- tests/conftest.py | 26 +++++++++++--------------- tests/web/test_outputs.py | 13 ++++++++++--- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fb15bb8b..fb9615b1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -23,8 +23,10 @@ from pymongo import MongoClient from bigchaindb.common import crypto from bigchaindb.log import setup_logging from bigchaindb.tendermint_utils import key_from_base64 +from bigchaindb.backend import schema from bigchaindb.common.crypto import (key_pair_from_ed25519_key, public_key_from_ed25519_key) +from bigchaindb.common.exceptions import DatabaseDoesNotExist from bigchaindb.lib import Block @@ -113,17 +115,12 @@ def _configure_bigchaindb(request): @pytest.fixture(scope='session') def _setup_database(_configure_bigchaindb): from bigchaindb import config - from bigchaindb.backend import connect, schema - from bigchaindb.common.exceptions import DatabaseDoesNotExist + from bigchaindb.backend import connect print('Initializing test db') dbname = config['database']['name'] conn = connect() - try: - schema.drop_database(conn, dbname) - except DatabaseDoesNotExist: - pass - + _drop_db(conn, dbname) schema.init_database(conn) print('Finishing init database') @@ -131,10 +128,7 @@ def _setup_database(_configure_bigchaindb): print('Deleting `{}` database'.format(dbname)) conn = connect() - try: - schema.drop_database(conn, dbname) - except DatabaseDoesNotExist: - pass + _drop_db(conn, dbname) print('Finished deleting `{}`'.format(dbname)) @@ -270,7 +264,6 @@ def signed_create_tx(alice, create_tx): return create_tx.sign([alice.private_key]) -@pytest.mark.abci @pytest.fixture def posted_create_tx(b, signed_create_tx): res = b.post_transaction(signed_create_tx, 'broadcast_tx_commit') @@ -321,8 +314,7 @@ def inputs(user_pk, b, alice): @pytest.fixture def dummy_db(request): - from bigchaindb.backend import connect, schema - from bigchaindb.common.exceptions import DatabaseDoesNotExist + from bigchaindb.backend import connect conn = connect() dbname = request.fixturename @@ -330,9 +322,14 @@ def dummy_db(request): if xdist_suffix: dbname = '{}_{}'.format(dbname, xdist_suffix) + _drop_db(conn, dbname) # make sure we start with a clean DB schema.init_database(conn, dbname) yield dbname + _drop_db(conn, dbname) + + +def _drop_db(conn, dbname): try: schema.drop_database(conn, dbname) except DatabaseDoesNotExist: @@ -428,7 +425,6 @@ def event_loop(): loop.close() -@pytest.mark.bdb @pytest.fixture(scope='session') def abci_server(): from abci import ABCIServer diff --git a/tests/web/test_outputs.py b/tests/web/test_outputs.py index 77a3f258..0e0267fe 100644 --- a/tests/web/test_outputs.py +++ b/tests/web/test_outputs.py @@ -5,11 +5,12 @@ import pytest from unittest.mock import MagicMock, patch -pytestmark = [pytest.mark.bdb, pytest.mark.usefixtures('inputs')] OUTPUTS_ENDPOINT = '/api/v1/outputs/' +@pytest.mark.bdb +@pytest.mark.userfixtures('inputs') def test_get_outputs_endpoint(client, user_pk): m = MagicMock() m.txid = 'a' @@ -38,6 +39,8 @@ def test_get_outputs_endpoint_unspent(client, user_pk): gof.assert_called_once_with(user_pk, False) +@pytest.mark.bdb +@pytest.mark.userfixtures('inputs') def test_get_outputs_endpoint_spent(client, user_pk): m = MagicMock() m.txid = 'a' @@ -51,11 +54,15 @@ def test_get_outputs_endpoint_spent(client, user_pk): gof.assert_called_once_with(user_pk, True) +@pytest.mark.bdb +@pytest.mark.userfixtures('inputs') def test_get_outputs_endpoint_without_public_key(client): res = client.get(OUTPUTS_ENDPOINT) assert res.status_code == 400 +@pytest.mark.bdb +@pytest.mark.userfixtures('inputs') def test_get_outputs_endpoint_with_invalid_public_key(client): expected = {'message': {'public_key': 'Invalid base58 ed25519 key'}} 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 +@pytest.mark.bdb +@pytest.mark.userfixtures('inputs') def test_get_outputs_endpoint_with_invalid_spent(client, user_pk): expected = {'message': {'spent': 'Boolean value must be "true" or "false" (lowercase)'}} 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.bdb -@pytest.mark.usefixtures('inputs') def test_get_divisble_transactions_returns_500(b, client): from bigchaindb.models import Transaction from bigchaindb.common import crypto