Beispiel #1
0
    def test_reload(self):
        # load initial config
        config = SampleConfig(loaders=[EnvLoader()])
        self.assertEqual(config.STRING_PROP, 'let\'s see if overrides work')

        # set something else in env
        os.environ['STRING_PROP'] = 'new value!'

        config.reload()
        self.assertEqual(config.STRING_PROP, 'new value!')
Beispiel #2
0
    def test_allow_nones(self):
        # test that intentional None value in first priority loader is not overriden
        config_dict = {
            'STRING_PROP': '1',
            'INT_PROP': 3,
            'ANY_TYPE_PROP': None
        }

        os.environ['ANY_TYPE_PROP'] = 'this should not get through'
        self.env_keys_set.append('ANY_TYPE_PROP')

        config_env_second = SampleConfig(loaders=[DictLoader(config_dict), EnvLoader()])
        self.assertIsNone(config_env_second.ANY_TYPE_PROP)
Beispiel #3
0
    def test_loader_priority(self):
        config_dict = {
            'STRING_PROP': '1',
            'INT_PROP': '2',
            'ANY_TYPE_PROP': [1, 2, 3],
            'NOT_A_PROPERTY': 'boo'
        }

        # construct config with env overrides
        config_with_env = SampleConfig(loaders=[EnvLoader(), DictLoader(config_dict)])

        self.assertEqual(config_with_env.STRING_PROP, 'let\'s see if overrides work')
        self.assertEqual(config_with_env.INT_PROP, 2)
        self.assertEqual(config_with_env.ONLY_IN_ENV, 'this is only in the env!')
        with self.assertRaises(AttributeError):
            config_with_env.NOT_A_PROPERTY
Beispiel #4
0
    def test_env_loader(self):
        os.environ['EXISTING_KEY'] = 'hello'

        loader = EnvLoader()

        # change the env after loader is initialized
        os.environ['EXISTING_KEY'] = 'world'
        os.environ['NEW_KEY'] = 'brand_new'

        self.assertTrue(loader.exists('EXISTING_KEY'))
        self.assertTrue(loader.exists('NEW_KEY'))
        self.assertFalse(loader.exists('BAD_KEY'))

        self.assertEqual(loader.get('EXISTING_KEY'), 'world')
        self.assertEqual(loader.get('NEW_KEY'), 'brand_new')