Pretty message when dropping a non-existent database

This commit is contained in:
Anuj 2017-04-02 17:53:39 +05:30
parent 69190fed67
commit 09866920af
2 changed files with 18 additions and 2 deletions

View File

@ -12,7 +12,8 @@ import sys
from bigchaindb.common import crypto
from bigchaindb.common.exceptions import (StartupError,
DatabaseAlreadyExists,
KeypairNotFoundException)
KeypairNotFoundException,
DatabaseDoesNotExist)
import bigchaindb
from bigchaindb import backend, processes
from bigchaindb.backend import schema
@ -166,7 +167,10 @@ def run_drop(args):
conn = backend.connect()
dbname = bigchaindb.config['database']['name']
schema.drop_database(conn, dbname)
try:
schema.drop_database(conn, dbname)
except DatabaseDoesNotExist:
print("Cannot drop '{name}'. The database does not exist.".format(name=dbname), file=sys.stderr)
@configure_bigchaindb

View File

@ -149,6 +149,18 @@ def test_drop_db_when_interactive_yes(mock_db_drop, monkeypatch):
assert mock_db_drop.called
@patch('bigchaindb.backend.schema.drop_database')
def test_drop_db_when_db_does_not_exist(mock_db_drop, capsys):
from bigchaindb.commands.bigchain import run_drop
from bigchaindb.common.exceptions import DatabaseDoesNotExist
args = Namespace(config=None, yes=True)
mock_db_drop.side_effect = DatabaseDoesNotExist
run_drop(args)
output_message = capsys.readouterr()[1]
assert output_message == "Cannot drop 'bigchain'. The database does not exist.\n"
@patch('bigchaindb.backend.schema.drop_database')
def test_drop_db_does_not_drop_when_interactive_no(mock_db_drop, monkeypatch):
from bigchaindb.commands.bigchain import run_drop