Handle case when db already exists

This commit is contained in:
Sylvain Bellemare 2016-02-14 20:05:16 +01:00
parent 61c9268294
commit 35344d87fa
2 changed files with 14 additions and 1 deletions

View File

@ -64,7 +64,14 @@ def run_configure(args, skip_if_exists=False):
def run_init(args):
"""Initialize the database"""
bigchaindb.config_utils.file_config(args.config)
db.init()
# TODO Provide mechanism to:
# 1. prompt the user to inquire whether they wish to drop the db
# 2. force the init, (e.g., via -f flag)
try:
db.init()
except DatabaseAlreadyExists:
print('The database already exists.')
print('If you wish to re-initialize it, first drop it.')
def run_drop(args):

View File

@ -53,3 +53,9 @@ def test_bigchain_show_config(capsys, mock_file_config):
pprint(config)
expected_outout_config, _ = capsys.readouterr()
assert output_config == expected_outout_config
def test_bigchain_run_init_when_db_exists(mock_file_config, mock_db_init_with_existing_db):
from bigchaindb.commands.bigchain import run_init
args = Namespace(config=None)
run_init(args)