Retrieve default backend from env if set.

Fixed tests.
This commit is contained in:
Rodolphe Marques 2017-01-31 10:34:45 +01:00
parent 555745abbf
commit fafdac2523
2 changed files with 30 additions and 7 deletions

View File

@ -20,6 +20,11 @@ _database_mongodb = {
'replicaset': os.environ.get('BIGCHAINDB_DATABASE_REPLICASET', 'bigchain-rs'),
}
_database_map = {
'mongodb': _database_mongodb,
'rethinkdb': _database_rethinkdb
}
config = {
'server': {
# Note: this section supports all the Gunicorn settings:
@ -28,7 +33,9 @@ config = {
'workers': None, # if none, the value will be cpu_count * 2 + 1
'threads': None, # if none, the value will be cpu_count * 2 + 1
},
'database': _database_rethinkdb,
'database': _database_map[
os.environ.get('BIGCHAINDB_DATABASE_BACKEND', 'rethinkdb')
],
'keypair': {
'public': None,
'private': None,

View File

@ -131,6 +131,27 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
from bigchaindb import config_utils
config_utils.autoconfigure()
backend = request.config.getoption('--database-backend')
database_rethinkdb = {
'backend': 'rethinkdb',
'host': 'test-host',
'port': 4242,
'name': 'test-dbname',
}
database_mongodb = {
'backend': 'mongodb',
'host': 'test-host',
'port': 4242,
'name': 'test-dbname',
'replicaset': 'bigchain-rs',
}
database = {}
if backend == 'mongodb':
database = database_mongodb
elif backend == 'rethinkdb':
database = database_rethinkdb
assert bigchaindb.config == {
'CONFIGURED': True,
'server': {
@ -138,12 +159,7 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
'workers': None,
'threads': None,
},
'database': {
'backend': request.config.getoption('--database-backend'),
'host': 'test-host',
'port': 4242,
'name': 'test-dbname',
},
'database': database,
'keypair': {
'public': None,
'private': None,