Merge branch 'issue558' of https://github.com/ShipChain/cement into ShipChain-issue558

This commit is contained in:
BJ Dierkes 2019-05-17 20:13:35 -05:00
commit e4f9f3cca9
2 changed files with 14 additions and 2 deletions

View File

@ -152,12 +152,12 @@ class ConfigParserConfigHandler(config.ConfigHandler, RawConfigParser):
env_var = re.sub('[^0-9a-zA-Z]+', '_', env_var)
return env_var
def get(self, section, key):
def get(self, section, key, **kwargs):
env_var = self._get_env_var(section, key)
if env_var in os.environ.keys():
return os.environ[env_var]
else:
return RawConfigParser.get(self, section, key)
return RawConfigParser.get(self, section, key, **kwargs)
def has_section(self, section):
return RawConfigParser.has_section(self, section)

View File

@ -54,3 +54,15 @@ def test_env_var_override():
assert app.config.get('dummy', 'foo') == 'dummy-not-bar'
section_dict = app.config.get_section_dict('dummy')
assert section_dict['foo'] == 'dummy-not-bar'
def test_get_boolean():
with TestApp(config_section='testapp') as app:
app.config.set('testapp', 'foobool', 'true')
assert app.config['testapp'].getboolean('foobool') is True
app.config.set('testapp', 'foobool', 'no')
assert app.config['testapp'].getboolean('foobool') is False
os.environ['TESTAPP_FOOBOOL'] = '1'
assert app.config['testapp'].getboolean('foobool') is True