Merge pull request #1366 from anujism/bug/437/pretty-msg-drop-nonexistent-db

Bug-437 Pretty message when drop nonexistent db
This commit is contained in:
Rodolphe Marques 2017-04-04 11:29:33 +02:00 committed by GitHub
commit cd0a2dcdb7
2 changed files with 20 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,20 @@ 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 import config
from bigchaindb.commands.bigchaindb 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 '{name}'. The database does not exist.\n".format(
name=config['database']['name'])
@patch('bigchaindb.backend.schema.drop_database')
def test_drop_db_does_not_drop_when_interactive_no(mock_db_drop, monkeypatch):
from bigchaindb.commands.bigchaindb import run_drop