Fail if config file not found

This commit is contained in:
vrde 2017-05-18 13:08:46 +02:00 committed by Sylvain Bellemare
parent 78e3f08728
commit 6f5c55c044
4 changed files with 21 additions and 4 deletions

View File

@ -238,7 +238,10 @@ def autoconfigure(filename=None, config=None, force=False):
try:
newconfig = update(newconfig, file_config(filename=filename))
except FileNotFoundError as e:
logger.warning('Cannot find config file `%s`.' % e.filename)
if filename:
raise
else:
logger.info('Cannot find config file `%s`.' % e.filename)
# override configuration with env variables
newconfig = env_config(newconfig)

View File

@ -88,11 +88,12 @@ def test_bigchain_show_config(capsys):
assert output_config == config
@pytest.mark.usefixtures('ignore_local_config_file')
def test_bigchain_export_my_pubkey_when_pubkey_set(capsys, monkeypatch):
from bigchaindb import config
from bigchaindb.commands.bigchaindb import run_export_my_pubkey
args = Namespace(config='dummy')
args = Namespace(config=None)
# so in run_export_my_pubkey(args) below,
# filename=args.config='dummy' is passed to autoconfigure().
# We just assume autoconfigure() works and sets
@ -107,11 +108,12 @@ def test_bigchain_export_my_pubkey_when_pubkey_set(capsys, monkeypatch):
assert 'Charlie_Bucket' in lines
@pytest.mark.usefixtures('ignore_local_config_file')
def test_bigchain_export_my_pubkey_when_pubkey_not_set(monkeypatch):
from bigchaindb import config
from bigchaindb.commands.bigchaindb import run_export_my_pubkey
args = Namespace(config='dummy')
args = Namespace(config=None)
monkeypatch.setitem(config['keypair'], 'public', None)
# assert that run_export_my_pubkey(args) raises SystemExit:
with pytest.raises(SystemExit) as exc_info:

View File

@ -199,7 +199,7 @@ def _genesis(_bdb, genesis_block):
@pytest.fixture
def ignore_local_config_file(monkeypatch):
def mock_file_config(filename=None):
raise FileNotFoundError()
return {}
monkeypatch.setattr('bigchaindb.config_utils.file_config',
mock_file_config)

View File

@ -257,6 +257,18 @@ def test_autoconfigure_env_precedence(monkeypatch):
assert bigchaindb.config['server']['bind'] == 'localhost:9985'
def test_autoconfigure_explicit_file(monkeypatch):
from bigchaindb import config_utils
def file_config(*args, **kwargs):
raise FileNotFoundError()
monkeypatch.setattr('bigchaindb.config_utils.file_config', file_config)
with pytest.raises(FileNotFoundError):
config_utils.autoconfigure(filename='autoexec.bat')
def test_update_config(monkeypatch):
import bigchaindb
from bigchaindb import config_utils