diff --git a/bigchaindb/commands/bigchain.py b/bigchaindb/commands/bigchain.py index 77746b18..159668f4 100644 --- a/bigchaindb/commands/bigchain.py +++ b/bigchaindb/commands/bigchain.py @@ -8,6 +8,7 @@ import argparse import bigchaindb import bigchaindb.config_utils from bigchaindb import db +from bigchaindb.exceptions import DatabaseAlreadyExists from bigchaindb.commands.utils import base_parser, start from bigchaindb.processes import Processes from bigchaindb.crypto import generate_key_pair @@ -75,7 +76,7 @@ def run_start(args): bigchaindb.config_utils.file_config(args.config) try: db.init() - except db.DatabaseAlreadyExistsException: + except DatabaseAlreadyExists: pass p = Processes() logger.info('Start bigchaindb main process') diff --git a/tests/test_commands.py b/tests/test_commands.py new file mode 100644 index 00000000..4cfc0db8 --- /dev/null +++ b/tests/test_commands.py @@ -0,0 +1,39 @@ +from argparse import Namespace + +import pytest + + +@pytest.fixture +def mock_run_configure(monkeypatch): + from bigchaindb.commands import bigchain + monkeypatch.setattr(bigchain, 'run_configure', lambda *args, **kwargs: None) + + +@pytest.fixture +def mock_file_config(monkeypatch): + from bigchaindb import config_utils + monkeypatch.setattr(config_utils, 'file_config', lambda *args: None) + + +@pytest.fixture +def mock_db_init_with_existing_db(monkeypatch): + from bigchaindb import db + from bigchaindb.exceptions import DatabaseAlreadyExists + + def mockreturn(): + raise DatabaseAlreadyExists + + monkeypatch.setattr(db, 'init', mockreturn) + + +@pytest.fixture +def mock_processes_start(monkeypatch): + from bigchaindb.processes import Processes + monkeypatch.setattr(Processes, 'start', lambda *args: None) + + +def test_bigchain_run_start(mock_run_configure, mock_file_config, + mock_processes_start, mock_db_init_with_existing_db): + from bigchaindb.commands.bigchain import run_start + args = Namespace(config=None, yes=True) + run_start(args)