diff --git a/bigchaindb/backend/connection.py b/bigchaindb/backend/connection.py index 2fc7d856..f96b8bbf 100644 --- a/bigchaindb/backend/connection.py +++ b/bigchaindb/backend/connection.py @@ -1,3 +1,4 @@ +import bigchaindb from bigchaindb.common.exceptions import ConfigurationError from importlib import import_module @@ -7,7 +8,11 @@ BACKENDS = { } -def connect(backend, host, port, dbname): +def connect(backend, host=None, port=None, name=None): + host = host or bigchaindb.config['database']['host'] + port = port or bigchaindb.config['database']['port'] + name = name or bigchaindb.config['database']['name'] + try: module_name, _, class_name = BACKENDS[backend].rpartition('.') Class = getattr(import_module(module_name), class_name) @@ -17,7 +22,7 @@ def connect(backend, host, port, dbname): except (ImportError, AttributeError) as exc: raise ConfigurationError('Error loading backend `{}`'.format(backend)) from exc - return Class(host, port, dbname) + return Class(host, port, name) class Connection: diff --git a/bigchaindb/core.py b/bigchaindb/core.py index 3cc669b8..fdf7588e 100644 --- a/bigchaindb/core.py +++ b/bigchaindb/core.py @@ -10,8 +10,7 @@ from bigchaindb.common.transaction import TransactionLink, Asset import bigchaindb -from bigchaindb import backend -from bigchaindb import config_utils, util +from bigchaindb import backend, config_utils, util from bigchaindb.consensus import BaseConsensusRules from bigchaindb.models import Block, Transaction diff --git a/tests/backend/test_connection.py b/tests/backend/test_connection.py index 4300141f..bdc336a9 100644 --- a/tests/backend/test_connection.py +++ b/tests/backend/test_connection.py @@ -10,7 +10,7 @@ def test_get_connection_returns_the_correct_instance(): 'backend': 'rethinkdb', 'host': 'localhost', 'port': 28015, - 'dbname': 'test' + 'name': 'test' } conn = connect(**config)