From d8256d50f2b84de4836a4ccc3a240ce4f478e0e1 Mon Sep 17 00:00:00 2001 From: Ryan Henderson Date: Thu, 15 Dec 2016 14:16:30 +0100 Subject: [PATCH] remove rethinkdb calls (#953) * remove rethinkdb calls from db/conftest.py --- tests/assets/conftest.py | 8 +------ tests/db/conftest.py | 43 ++++++++++------------------------- tests/integration/conftest.py | 7 +----- tests/pipelines/conftest.py | 7 +----- tests/web/conftest.py | 7 +----- 5 files changed, 16 insertions(+), 56 deletions(-) diff --git a/tests/assets/conftest.py b/tests/assets/conftest.py index 1a3a77e2..3dcfa347 100644 --- a/tests/assets/conftest.py +++ b/tests/assets/conftest.py @@ -8,12 +8,6 @@ def restore_config(request, node_config): config_utils.set_config(node_config) -@pytest.fixture(scope='module', autouse=True) +@pytest.fixture(scope='function', autouse=True) def setup_database(request, node_config): conftest.setup_database(request, node_config) - - -@pytest.fixture(scope='function', autouse=True) -def cleanup_tables(request, node_config): - conftest.cleanup_tables(request, node_config) - diff --git a/tests/db/conftest.py b/tests/db/conftest.py index 4959e2d2..d58d0e8c 100644 --- a/tests/db/conftest.py +++ b/tests/db/conftest.py @@ -7,12 +7,11 @@ Tasks: """ import pytest -import rethinkdb as r from bigchaindb import Bigchain from bigchaindb.backend import connect, schema from bigchaindb.common import crypto -from bigchaindb.common.exceptions import DatabaseAlreadyExists +from bigchaindb.common.exceptions import DatabaseDoesNotExist USER2_SK, USER2_PK = crypto.generate_key_pair() @@ -24,52 +23,34 @@ def restore_config(request, node_config): config_utils.set_config(node_config) -@pytest.fixture(scope='module', autouse=True) +@pytest.fixture(scope='function', autouse=True) def setup_database(request, node_config): print('Initializing test db') db_name = node_config['database']['name'] conn = connect() - if conn.run(r.db_list().contains(db_name)): - conn.run(r.db_drop(db_name)) - try: - schema.init_database() - except DatabaseAlreadyExists: - print('Database already exists.') + 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)) - conn = connect() try: - conn.run(r.db_drop(db_name)) - except r.ReqlOpFailedError as e: - if e.message != 'Database `{}` does not exist.'.format(db_name): - raise + schema.drop_database(conn, db_name) + except DatabaseDoesNotExist: + pass + print('Finished deleting `{}`'.format(db_name)) request.addfinalizer(fin) -@pytest.fixture(scope='function', autouse=True) -def cleanup_tables(request, node_config): - db_name = node_config['database']['name'] - - def fin(): - conn = connect() - try: - conn.run(r.db(db_name).table('bigchain').delete()) - conn.run(r.db(db_name).table('backlog').delete()) - conn.run(r.db(db_name).table('votes').delete()) - except r.ReqlOpFailedError as e: - if e.message != 'Database `{}` does not exist.'.format(db_name): - raise - - request.addfinalizer(fin) - - @pytest.fixture def inputs(user_pk): from bigchaindb.models import Transaction diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 5ac81cb3..d3520ed4 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -11,16 +11,11 @@ def restore_config(request, node_config): config_utils.set_config(node_config) -@pytest.fixture(scope='module', autouse=True) +@pytest.fixture(scope='function', autouse=True) def setup_database(request, node_config): conftest.setup_database(request, node_config) -@pytest.fixture(scope='function', autouse=True) -def cleanup_tables(request, node_config): - conftest.cleanup_tables(request, node_config) - - @pytest.fixture def processes(b): b.create_genesis_block() diff --git a/tests/pipelines/conftest.py b/tests/pipelines/conftest.py index a949c947..3dcfa347 100644 --- a/tests/pipelines/conftest.py +++ b/tests/pipelines/conftest.py @@ -8,11 +8,6 @@ def restore_config(request, node_config): config_utils.set_config(node_config) -@pytest.fixture(scope='module', autouse=True) +@pytest.fixture(scope='function', autouse=True) def setup_database(request, node_config): conftest.setup_database(request, node_config) - - -@pytest.fixture(scope='function', autouse=True) -def cleanup_tables(request, node_config): - conftest.cleanup_tables(request, node_config) diff --git a/tests/web/conftest.py b/tests/web/conftest.py index 988b0912..af1b1852 100644 --- a/tests/web/conftest.py +++ b/tests/web/conftest.py @@ -8,16 +8,11 @@ def restore_config(request, node_config): config_utils.set_config(node_config) -@pytest.fixture(scope='module', autouse=True) +@pytest.fixture(scope='function', autouse=True) def setup_database(request, node_config): conftest.setup_database(request, node_config) -@pytest.fixture(scope='function', autouse=True) -def cleanup_tables(request, node_config): - conftest.cleanup_tables(request, node_config) - - @pytest.fixture def app(request, node_config): # XXX: For whatever reason this fixture runs before `restore_config`,