diff --git a/bigchaindb/config_utils.py b/bigchaindb/config_utils.py index 19caef90..df63e7c2 100644 --- a/bigchaindb/config_utils.py +++ b/bigchaindb/config_utils.py @@ -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 diff --git a/tests/utils/test_config_utils.py b/tests/utils/test_config_utils.py index eafcef08..cec7743f 100644 --- a/tests/utils/test_config_utils.py +++ b/tests/utils/test_config_utils.py @@ -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', } +