mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Fail if config file not found
This commit is contained in:
parent
5ae8c81474
commit
3995e22d4a
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user