mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Add defaults, fix import
This commit is contained in:
parent
2fd0aeca9f
commit
26c844ec22
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user