From a0761612ec671ed28482e952e7c7659e5344bfff Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 12 Feb 2016 15:01:56 +0100 Subject: [PATCH 1/3] Move db exception to the right module --- bigchaindb/db/utils.py | 8 ++------ bigchaindb/exceptions.py | 3 +++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/bigchaindb/db/utils.py b/bigchaindb/db/utils.py index 55ad7c03..d72a4f04 100644 --- a/bigchaindb/db/utils.py +++ b/bigchaindb/db/utils.py @@ -1,17 +1,13 @@ """Utils to initialize and drop the database.""" import logging - import rethinkdb as r - import bigchaindb +from bigchaindb import exceptions logger = logging.getLogger(__name__) -class DatabaseAlreadyExistsException(Exception): - pass - def get_conn(): '''Get the connection to the database.''' @@ -24,7 +20,7 @@ def init(): dbname = bigchaindb.config['database']['name'] if r.db_list().contains(dbname).run(conn): - raise DatabaseAlreadyExistsException('Database `{}` already exists'.format(dbname)) + raise exceptions.DatabaseAlreadyExistsException('Database `{}` already exists'.format(dbname)) logger.info('Create:') logger.info(' - database `%s`', dbname) diff --git a/bigchaindb/exceptions.py b/bigchaindb/exceptions.py index eb87ca25..07cb0155 100644 --- a/bigchaindb/exceptions.py +++ b/bigchaindb/exceptions.py @@ -19,3 +19,6 @@ class InvalidHash(Exception): class InvalidSignature(Exception): """Raised if there was an error checking the signature for a particular operation""" +class DatabaseAlreadyExistsException(Exception): + """Raised when trying to create the database but the db is already there""" + From 54e2818a62146cd3619d028af720ba534559e317 Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 12 Feb 2016 18:37:46 +0100 Subject: [PATCH 2/3] Respect PEP8. Respect Guido. --- bigchaindb/db/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bigchaindb/db/utils.py b/bigchaindb/db/utils.py index d72a4f04..bdb30ec6 100644 --- a/bigchaindb/db/utils.py +++ b/bigchaindb/db/utils.py @@ -1,7 +1,9 @@ """Utils to initialize and drop the database.""" import logging + import rethinkdb as r + import bigchaindb from bigchaindb import exceptions From 54e1c7e7039a65f74dcdeb0a074f4165b6b9d923 Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 12 Feb 2016 19:03:42 +0100 Subject: [PATCH 3/3] Simplify exception name --- bigchaindb/db/utils.py | 2 +- bigchaindb/exceptions.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bigchaindb/db/utils.py b/bigchaindb/db/utils.py index bdb30ec6..f3f4f5c7 100644 --- a/bigchaindb/db/utils.py +++ b/bigchaindb/db/utils.py @@ -22,7 +22,7 @@ def init(): dbname = bigchaindb.config['database']['name'] if r.db_list().contains(dbname).run(conn): - raise exceptions.DatabaseAlreadyExistsException('Database `{}` already exists'.format(dbname)) + raise exceptions.DatabaseAlreadyExists('Database `{}` already exists'.format(dbname)) logger.info('Create:') logger.info(' - database `%s`', dbname) diff --git a/bigchaindb/exceptions.py b/bigchaindb/exceptions.py index 07cb0155..964daefe 100644 --- a/bigchaindb/exceptions.py +++ b/bigchaindb/exceptions.py @@ -19,6 +19,6 @@ class InvalidHash(Exception): class InvalidSignature(Exception): """Raised if there was an error checking the signature for a particular operation""" -class DatabaseAlreadyExistsException(Exception): +class DatabaseAlreadyExists(Exception): """Raised when trying to create the database but the db is already there"""