def test_unrequired_with_default_values(self): """ Tests an evar that isn't required, but has a default. """ store = ConfigStore({ 'A_BOOL_SETTING': EnvironmentVariable( name='BOOL_EVAR', is_required=False, default_val='true', filters=[value_to_bool], ), }) store.load_values() self.assertTrue(store['A_BOOL_SETTING'])
def test_unrequired_without_default_values(self): """ Tests an evar that isn't required, and has no default. """ store = ConfigStore({ 'A_BOOL_SETTING': EnvironmentVariable( name='BOOL_EVAR', is_required=False, filters=[value_to_bool], ), }) store.load_values() # No value was specified in an evar. The default default value is # None, which gets filtered to False. self.assertEqual(store['A_BOOL_SETTING'], False)
def test_simple_load_and_filter(self): """ Tests a simple evar transformation. """ store = ConfigStore({ 'LOGLEVEL': EnvironmentVariable( name='LOGLEVEL', help_txt='The desired logging level (DEBUG|INFO|WARN|ERROR).', is_required=False, default_val='INFO', filters=[value_to_python_log_level], ) }) # The filter uppercases this and makes sure it's valid. os.environ['LOGLEVEL'] = 'info' store.load_values() # The end result is a properly formed Python logging level. self.assertEqual(store['LOGLEVEL'], logging.INFO)
values = ConfigStore({ 'SERVER': EnvironmentVariable( name='PLUGIN_SERVER', filters=[ value_to_none, validate_is_not_none, validate_devpi_server_url ], help_txt=( "Full path to the root of the devpi server. Make sure to include " "the protocol (and port if it's not standard).")), 'INDEX': EnvironmentVariable( name='PLUGIN_INDEX', filters=[value_to_none, validate_is_not_none], help_txt="The <user>/<repo> combo designating the index to upload to.", ), 'USERNAME': EnvironmentVariable( name='PLUGIN_USERNAME', filters=[value_to_none, validate_is_not_none], help_txt="The devpi username to login with before uploading.", ), 'PASSWORD': EnvironmentVariable( name='PLUGIN_PASSWORD', help_txt="The devpi user's password.", ), 'PACKAGE_PATH': EnvironmentVariable( name='PLUGIN_PACKAGE_PATH', filters=[value_to_none, validate_is_not_none], default_val=os.getcwd(), help_txt="Path to the package to upload.", ), })
def test_empty_store(self): """ Test empty ConfigStore being validated. """ store = ConfigStore({}) store.load_values()