bigchaindb/tests/utils/test_config_utils.py

40 lines
1.0 KiB
Python
Raw Normal View History

2016-02-10 19:55:33 +01:00
import copy
import pytest
import bigchaindb
2016-02-22 23:46:32 +01:00
from bigchaindb import exceptions
2016-02-10 19:55:33 +01:00
ORIGINAL_CONFIG = copy.deepcopy(bigchaindb.config)
@pytest.fixture(scope='function', autouse=True)
def clean_config():
bigchaindb.config = copy.deepcopy(ORIGINAL_CONFIG)
def test_bigchain_instance_is_initialized_when_conf_provided():
2016-02-15 11:25:56 +01:00
from bigchaindb import config_utils
2016-02-10 19:55:33 +01:00
assert 'CONFIGURED' not in bigchaindb.config
config_utils.dict_config({'keypair': {'public': 'a', 'private': 'b'}})
assert bigchaindb.config['CONFIGURED'] is True
2016-02-10 19:55:33 +01:00
b = bigchaindb.Bigchain()
assert b.me
assert b.me_private
def test_bigchain_instance_raises_when_not_configured(monkeypatch):
2016-02-15 11:25:56 +01:00
from bigchaindb import config_utils
2016-02-10 19:55:33 +01:00
assert 'CONFIGURED' not in bigchaindb.config
# We need to disable ``bigchaindb.config_utils.autoconfigure`` to avoid reading
# from existing configurations
monkeypatch.setattr(config_utils, 'autoconfigure', lambda: 0)
2016-02-22 23:46:32 +01:00
with pytest.raises(exceptions.KeypairNotFoundException):
2016-02-10 19:55:33 +01:00
bigchaindb.Bigchain()