Ejemplo n.º 1
0
    def test_should_give_priority_to_explicit_properties_rather_than_os_env_variables(self):
        # when
        os.environ['bf_bb'] = 'x'
        config = Config('dev', {'bb': 1})

        # then
        self.assertEqual(config.resolve('dev'), {'bb': 1})
        self.assertEqual(config.resolve(), {'bb': 1})
        self.assertEqual(config.resolve_property('bb', 'dev'), 1)
        self.assertEqual(config.resolve_property('bb'), 1)
Ejemplo n.º 2
0
 def test_should_smartly_resolve_properties_with_placeholders(self):
     # when
     config = Config('dev', {
                                'project_id': 'dev_project',
                                'topic': 'topic/{project_id}/my_topic}'
                            }) \
         .add_configuration('prod',
                            {
                                'project_id': 'prod_project',
                            })
     # then
     self.assertEqual(config.resolve_property('topic', 'dev'),  'topic/dev_project/my_topic}')
     self.assertEqual(config.resolve_property('topic', 'prod'), 'topic/prod_project/my_topic}')
Ejemplo n.º 3
0
    def test_should_resolve_env_variables_laizyly_when_calling_resolve_property(self):
        # when
        config = Config('dev', {'a': 'dev1'})

        #then
        self.assertEqual(config.resolve(), {'a': 'dev1'})
        self.assertEqual(config.resolve_property('a'), 'dev1')
        self.assertEqual(config.resolve_property('a', 'dev'), 'dev1')
        with self.assertRaises(ValueError):
            config.resolve_property('b')

        # when
        os.environ['bf_b'] = 'b_from_env'

        # then
        self.assertEqual(config.resolve(), {'a': 'dev1'})
        self.assertEqual(config.resolve_property('b'), 'b_from_env')
        self.assertEqual(config.resolve_property('b', 'dev'), 'b_from_env')
        with self.assertRaises(ValueError):
            config.resolve_property('c')