Added some constants to simplify test

This commit is contained in:
Rodolphe Marques 2017-01-31 13:51:49 +01:00
parent 4740150f6d
commit 2c26468cea

View File

@ -10,8 +10,13 @@ ORIGINAL_CONFIG = copy.deepcopy(bigchaindb._config)
@pytest.fixture(scope='function', autouse=True) @pytest.fixture(scope='function', autouse=True)
def clean_config(monkeypatch): def clean_config(monkeypatch, request):
monkeypatch.setattr('bigchaindb.config', copy.deepcopy(ORIGINAL_CONFIG))
import bigchaindb
original_config = copy.deepcopy(ORIGINAL_CONFIG)
backend = request.config.getoption('--database-backend')
original_config['database'] = bigchaindb._database_map[backend]
monkeypatch.setattr('bigchaindb.config', original_config)
def test_bigchain_instance_is_initialized_when_conf_provided(request): def test_bigchain_instance_is_initialized_when_conf_provided(request):
@ -104,48 +109,55 @@ def test_env_config(monkeypatch):
def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request): def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
# constants
DATABASE_HOST = 'test-host'
DATABASE_NAME = 'test-dbname'
DATABASE_PORT = 4242
DATABASE_BACKEND = request.config.getoption('--database-backend')
SERVER_BIND = '1.2.3.4:56'
KEYRING = 'pubkey_0:pubkey_1:pubkey_2'
file_config = { file_config = {
'database': { 'database': {
'host': 'test-host', 'host': DATABASE_HOST
'backend': request.config.getoption('--database-backend')
}, },
'backlog_reassign_delay': 5 'backlog_reassign_delay': 5
} }
monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config) monkeypatch.setattr('bigchaindb.config_utils.file_config', lambda *args, **kwargs: file_config)
monkeypatch.setattr('os.environ', {'BIGCHAINDB_DATABASE_NAME': 'test-dbname', monkeypatch.setattr('os.environ', {'BIGCHAINDB_DATABASE_NAME': DATABASE_NAME,
'BIGCHAINDB_DATABASE_PORT': '4242', 'BIGCHAINDB_DATABASE_PORT': str(DATABASE_PORT),
'BIGCHAINDB_SERVER_BIND': '1.2.3.4:56', 'BIGCHAINDB_DATABASE_BACKEND': DATABASE_BACKEND,
'BIGCHAINDB_KEYRING': 'pubkey_0:pubkey_1:pubkey_2'}) 'BIGCHAINDB_SERVER_BIND': SERVER_BIND,
'BIGCHAINDB_KEYRING': KEYRING})
import bigchaindb import bigchaindb
from bigchaindb import config_utils from bigchaindb import config_utils
config_utils.autoconfigure() config_utils.autoconfigure()
backend = request.config.getoption('--database-backend')
database_rethinkdb = { database_rethinkdb = {
'backend': 'rethinkdb', 'backend': 'rethinkdb',
'host': 'test-host', 'host': DATABASE_HOST,
'port': 4242, 'port': DATABASE_PORT,
'name': 'test-dbname', 'name': DATABASE_NAME,
} }
database_mongodb = { database_mongodb = {
'backend': 'mongodb', 'backend': 'mongodb',
'host': 'test-host', 'host': DATABASE_HOST,
'port': 4242, 'port': DATABASE_PORT,
'name': 'test-dbname', 'name': DATABASE_NAME,
'replicaset': 'bigchain-rs', 'replicaset': 'bigchain-rs',
} }
database = {} database = {}
if backend == 'mongodb': if DATABASE_BACKEND == 'mongodb':
database = database_mongodb database = database_mongodb
elif backend == 'rethinkdb': elif DATABASE_BACKEND == 'rethinkdb':
database = database_rethinkdb database = database_rethinkdb
assert bigchaindb.config == { assert bigchaindb.config == {
'CONFIGURED': True, 'CONFIGURED': True,
'server': { 'server': {
'bind': '1.2.3.4:56', 'bind': SERVER_BIND,
'workers': None, 'workers': None,
'threads': None, 'threads': None,
}, },
@ -154,7 +166,7 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
'public': None, 'public': None,
'private': None, 'private': None,
}, },
'keyring': ['pubkey_0', 'pubkey_1', 'pubkey_2'], 'keyring': KEYRING.split(':'),
'statsd': { 'statsd': {
'host': 'localhost', 'host': 'localhost',
'port': 8125, 'port': 8125,