# HG changeset patch # User David Douard # Date 1479900244 -3600 # Node ID 2e1a1ebd4730a1eb79c2886bfb628df7aca4b16c # Parent 882bd17344c216f94375801ccc8e220c7d6990a1 [cwconfig] ensure CubicWebNoAppConfiguration returns a typed value (closes #16364459) diff -r 882bd17344c2 -r 2e1a1ebd4730 cubicweb/cwconfig.py --- a/cubicweb/cwconfig.py Mon Nov 21 14:18:43 2016 +0100 +++ b/cubicweb/cwconfig.py Wed Nov 23 12:24:04 2016 +0100 @@ -202,7 +202,8 @@ from logilab.common.deprecation import deprecated from logilab.common.logging_ext import set_log_methods, init_log from logilab.common.configuration import (Configuration, Method, - ConfigurationMixIn, merge_options) + ConfigurationMixIn, merge_options, + _validate as lgc_validate) from cubicweb import (CW_SOFTWARE_ROOT, CW_MIGRATION_MAP, ConfigurationError, Binary, _) @@ -420,7 +421,11 @@ def __getitem__(self, key): """Get configuration option, by first looking at environmnent.""" file_value = super(CubicWebNoAppConfiguration, self).__getitem__(key) - return option_value_from_env(key, file_value) + value = option_value_from_env(key, file_value) + if value is not None: + option_def = self.get_option_def(key) + value = lgc_validate(value, option_def) + return value # static and class methods used to get instance independant resources ## @staticmethod diff -r 882bd17344c2 -r 2e1a1ebd4730 cubicweb/test/unittest_cwconfig.py --- a/cubicweb/test/unittest_cwconfig.py Mon Nov 21 14:18:43 2016 +0100 +++ b/cubicweb/test/unittest_cwconfig.py Wed Nov 23 12:24:04 2016 +0100 @@ -208,7 +208,7 @@ from cubes import file self.assertEqual(file.__path__, [join(self.custom_cubes_dir, 'file')]) - def test_config_value_from_environment(self): + def test_config_value_from_environment_str(self): self.assertIsNone(self.config['base-url']) os.environ['CW_BASE_URL'] = 'https://www.cubicweb.org' try: @@ -217,6 +217,24 @@ finally: del os.environ['CW_BASE_URL'] + def test_config_value_from_environment_int(self): + self.assertEqual(self.config['connections-pool-size'], 4) + os.environ['CW_CONNECTIONS_POOL_SIZE'] = '6' + try: + self.assertEqual(self.config['connections-pool-size'], 6) + finally: + del os.environ['CW_CONNECTIONS_POOL_SIZE'] + + def test_config_value_from_environment_yn(self): + self.assertEqual(self.config['allow-email-login'], False) + try: + for val, result in (('yes', True), ('no', False), + ('y', True), ('n', False),): + os.environ['CW_ALLOW_EMAIL_LOGIN'] = val + self.assertEqual(self.config['allow-email-login'], result) + finally: + del os.environ['CW_ALLOW_EMAIL_LOGIN'] + class FindPrefixTC(unittest.TestCase):