예제 #1
0
    def test_should_resolve_from_master_config_when_property_is_missing(self):
        #when
        config = Config('dev', {'a': 1})\
            .add_configuration('prod', {})

        # then
        self.assertEqual(config.resolve('dev'), {'a': 1})
        self.assertEqual(config.resolve('prod'), {'a': 1})
예제 #2
0
    def test_should_support_hierarchical_configuration(self):
        # when
        config = Config('dev', {'a': 1, 'b': 2})\
            .add_configuration('prod', {'a': 5, 'b':10, 'c':20})

        # then
        self.assertEqual(config.resolve('dev'), {'a': 1, 'b': 2})
        self.assertEqual(config.resolve('prod'), {'a': 5, 'b': 10, 'c': 20})
예제 #3
0
    def test_should_give_priority_to_explicit_properties_rather_than_os_env_variables(
            self):
        # when
        os.environ['bb'] = 'x'
        config = Config('dev', {'bb': 1, 'cc': 1})

        # then
        self.assertEqual(config.resolve('dev'), {'bb': 1, 'cc': 1})
예제 #4
0
    def test_should_resolve_from_default_config_given_by_os_env_variable(self):
        # when
        os.environ['env'] = 'prod'

        config = Config('prod', {'bb': 1}).add_configuration('dev', {'bb': 2})

        # then
        self.assertEqual(config.resolve(), {'bb': 1})
예제 #5
0
    def test_should_use_os_environment_variable_prefix_if_given(self):
        # when
        os.environ['my_namespace_b'] = 'x'
        config = Config('dev', {'b': None},
                        environment_variables_prefix='my_namespace_')

        # then
        self.assertEqual(config.resolve('dev'), {'b': 'x'})
예제 #6
0
    def test_should_resolve_to_os_env_variable_when_property_value_is_None(
            self):
        # when
        os.environ['b'] = 'x'
        config = Config('dev', {'a': 1, 'b': None})

        # then
        self.assertEqual(config.resolve('dev'), {'a': 1, 'b': 'x'})
예제 #7
0
    def test_should_resolve_from_config_given_by_os_env_variable_with_prefix(
            self):
        # when
        os.environ['bq_env'] = 'prod'

        config = Config('prod', {'bb': 1}, environment_variables_prefix='bq_')

        # then
        self.assertEqual(config.resolve(), {'bb': 1})
예제 #8
0
    def test_should_resolve_explicit_properties_in_simple_config(self):
        # when
        config = Config('dev', {'a': 1, 'b': '2'})

        #expect
        self.assertEqual(config.resolve('dev'), {'a': 1, 'b': '2'})