def get_settings_loaders():
    """Return a list of settings loader objects for this environment."""
    # Pull configuration from env, then test settings file (if testing), then a settings file
    LOCAL_CONFIG_PATH = in_same_dir(__file__, "local_config.json")
    SETTINGS_PATH = os.environ.get("SETTINGS_PATH", LOCAL_CONFIG_PATH)
    loaders = [EnvLoader(), JsonFileLoader(SETTINGS_PATH)]
    return loaders
示例#2
0
import mock
import os
from unittest import TestCase

from grift.loaders import JsonFileLoader, EnvLoader, DictLoader, VaultLoader, VaultException
from grift.utils import in_same_dir

SAMPLE_FILE_PATH = in_same_dir(__file__, 'sample_config.json')


class TestBasicLoaders(TestCase):
    def test_dict_loader(self):
        config_dict = {'KEY': 'value', 'foo': 'bar'}

        loader = DictLoader(config_dict)
        self.assertTrue(loader.exists('KEY'))
        self.assertTrue('KEY' in loader)
        self.assertTrue(loader.exists('foo'))
        self.assertTrue('foo' in loader)
        self.assertFalse(loader.exists('bar'))
        self.assertFalse('bar' in loader)

        self.assertEqual(loader.get('KEY'), 'value')
        self.assertEqual(loader.get('foo'), 'bar')

    def test_env_loader(self):
        os.environ['EXISTING_KEY'] = 'hello'

        loader = EnvLoader()

        # change the env after loader is initialized