mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Add explicit tests for update_types
This commit is contained in:
parent
820a14baa7
commit
1ddfa2becb
@ -113,12 +113,10 @@ def env_config(config):
|
||||
return map_leafs(load_from_env, config)
|
||||
|
||||
|
||||
def update_types(config):
|
||||
def update_types(config, reference, list_sep=':'):
|
||||
"""Return a new configuration where all the values types
|
||||
are aligned with the ones in the default configuration"""
|
||||
|
||||
reference = bigchaindb.config
|
||||
|
||||
def _coerce(current, value):
|
||||
# Coerce a value to the `current` type.
|
||||
try:
|
||||
@ -130,7 +128,7 @@ def update_types(config):
|
||||
# is a string.
|
||||
if isinstance(current, list) and isinstance(value, str):
|
||||
# If so, we use the colon as the separator
|
||||
return value.split(':')
|
||||
return value.split(list_sep)
|
||||
|
||||
try:
|
||||
# If we are here, we should try to apply the type
|
||||
@ -165,7 +163,7 @@ def dict_config(config):
|
||||
update made to ``bigchaindb.config`` will be lost.
|
||||
"""
|
||||
bigchaindb.config = copy.deepcopy(bigchaindb._config)
|
||||
update(bigchaindb.config, update_types(config))
|
||||
update(bigchaindb.config, update_types(config, bigchaindb.config))
|
||||
bigchaindb.config['CONFIGURED'] = True
|
||||
|
||||
|
||||
|
@ -93,6 +93,27 @@ def test_map_leafs_iterator():
|
||||
}
|
||||
|
||||
|
||||
def test_update_types():
|
||||
from bigchaindb import config_utils
|
||||
|
||||
raw = {
|
||||
'a_string': 'test',
|
||||
'an_int': '42',
|
||||
'a_float': '3.14',
|
||||
'a_list': 'a:b:c',
|
||||
}
|
||||
|
||||
reference = {
|
||||
'a_string': 'test',
|
||||
'an_int': 42,
|
||||
'a_float': 3.14,
|
||||
'a_list': ['a', 'b', 'c'],
|
||||
}
|
||||
|
||||
result = config_utils.update_types(raw, reference)
|
||||
assert result == reference
|
||||
|
||||
|
||||
def test_env_config(monkeypatch):
|
||||
monkeypatch.setattr('os.environ', {'BIGCHAINDB_DATABASE_HOST': 'test-host',
|
||||
'BIGCHAINDB_DATABASE_PORT': 'test-port'})
|
||||
@ -143,3 +164,4 @@ def test_autoconfigure_read_both_from_file_and_env(monkeypatch):
|
||||
'api_endpoint': 'http://localhost:9984/api/v1',
|
||||
'consensus_plugin': 'default',
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user