Fail if config file not found
This commit is contained in:
parent
78e3f08728
commit
6f5c55c044
|
@ -238,7 +238,10 @@ def autoconfigure(filename=None, config=None, force=False):
|
||||||
try:
|
try:
|
||||||
newconfig = update(newconfig, file_config(filename=filename))
|
newconfig = update(newconfig, file_config(filename=filename))
|
||||||
except FileNotFoundError as e:
|
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
|
# override configuration with env variables
|
||||||
newconfig = env_config(newconfig)
|
newconfig = env_config(newconfig)
|
||||||
|
|
|
@ -88,11 +88,12 @@ def test_bigchain_show_config(capsys):
|
||||||
assert output_config == config
|
assert output_config == config
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('ignore_local_config_file')
|
||||||
def test_bigchain_export_my_pubkey_when_pubkey_set(capsys, monkeypatch):
|
def test_bigchain_export_my_pubkey_when_pubkey_set(capsys, monkeypatch):
|
||||||
from bigchaindb import config
|
from bigchaindb import config
|
||||||
from bigchaindb.commands.bigchaindb import run_export_my_pubkey
|
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,
|
# so in run_export_my_pubkey(args) below,
|
||||||
# filename=args.config='dummy' is passed to autoconfigure().
|
# filename=args.config='dummy' is passed to autoconfigure().
|
||||||
# We just assume autoconfigure() works and sets
|
# 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
|
assert 'Charlie_Bucket' in lines
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures('ignore_local_config_file')
|
||||||
def test_bigchain_export_my_pubkey_when_pubkey_not_set(monkeypatch):
|
def test_bigchain_export_my_pubkey_when_pubkey_not_set(monkeypatch):
|
||||||
from bigchaindb import config
|
from bigchaindb import config
|
||||||
from bigchaindb.commands.bigchaindb import run_export_my_pubkey
|
from bigchaindb.commands.bigchaindb import run_export_my_pubkey
|
||||||
|
|
||||||
args = Namespace(config='dummy')
|
args = Namespace(config=None)
|
||||||
monkeypatch.setitem(config['keypair'], 'public', None)
|
monkeypatch.setitem(config['keypair'], 'public', None)
|
||||||
# assert that run_export_my_pubkey(args) raises SystemExit:
|
# assert that run_export_my_pubkey(args) raises SystemExit:
|
||||||
with pytest.raises(SystemExit) as exc_info:
|
with pytest.raises(SystemExit) as exc_info:
|
||||||
|
|
|
@ -199,7 +199,7 @@ def _genesis(_bdb, genesis_block):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def ignore_local_config_file(monkeypatch):
|
def ignore_local_config_file(monkeypatch):
|
||||||
def mock_file_config(filename=None):
|
def mock_file_config(filename=None):
|
||||||
raise FileNotFoundError()
|
return {}
|
||||||
|
|
||||||
monkeypatch.setattr('bigchaindb.config_utils.file_config',
|
monkeypatch.setattr('bigchaindb.config_utils.file_config',
|
||||||
mock_file_config)
|
mock_file_config)
|
||||||
|
|
|
@ -257,6 +257,18 @@ def test_autoconfigure_env_precedence(monkeypatch):
|
||||||
assert bigchaindb.config['server']['bind'] == 'localhost:9985'
|
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):
|
def test_update_config(monkeypatch):
|
||||||
import bigchaindb
|
import bigchaindb
|
||||||
from bigchaindb import config_utils
|
from bigchaindb import config_utils
|
||||||
|
|
Loading…
Reference in New Issue