From fafdac252308314ade77e4ec175aef3869a74347 Mon Sep 17 00:00:00 2001 From: Rodolphe Marques Date: Tue, 31 Jan 2017 10:34:45 +0100 Subject: [PATCH] Retrieve default backend from env if set. Fixed tests. --- bigchaindb/__init__.py | 9 ++++++++- tests/test_config_utils.py | 28 ++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/bigchaindb/__init__.py b/bigchaindb/__init__.py index 315774e5..072c7b6b 100644 --- a/bigchaindb/__init__.py +++ b/bigchaindb/__init__.py @@ -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, diff --git a/tests/test_config_utils.py b/tests/test_config_utils.py index c1f63742..ebf630a9 100644 --- a/tests/test_config_utils.py +++ b/tests/test_config_utils.py @@ -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,