示例#1
0
    def test_override_config2(self):
        config = Config({
            'resources.i18n': {
                'timezone': 'America/Sao_Paulo',
            },
        })

        self.assertEqual(config.get_or_load('resources.i18n', 'locale'), 'en_US')
        self.assertEqual(config.get_or_load('resources.i18n', 'timezone'), 'America/Sao_Paulo')
示例#2
0
    def test_default_config(self):
        config = Config()

        from resources.template import default_config as template_config
        from resources.i18n import default_config as i18n_config

        self.assertEqual(config.get_or_load('resources.template', 'templates_dir'), template_config['templates_dir'])
        self.assertEqual(config.get_or_load('resources.i18n', 'locale'), i18n_config['locale'])
        self.assertEqual(config.get_or_load('resources.i18n', 'timezone'), i18n_config['timezone'])
示例#3
0
    def test_default_config_with_non_existing_key(self):
        config = Config()

        from resources.i18n import default_config as i18n_config

        # In the first time the module config will be loaded normally.
        self.assertEqual(config.get_or_load('resources.i18n', 'locale'), i18n_config['locale'])

        # In the second time it won't be loaded, but won't find the value and then use the default.
        self.assertEqual(config.get_or_load('resources.i18n', 'i_dont_exist', 'foo'), 'foo')
示例#4
0
    def test_override_config(self):
        config = Config({
            'resources.template': {
                'templates_dir': 'apps/templates'
            },
            'resources.i18n': {
                'locale': 'pt_BR',
                'timezone': 'America/Sao_Paulo',
            },
        })

        self.assertEqual(config.get_or_load('resources.template', 'templates_dir'), 'apps/templates')
        self.assertEqual(config.get_or_load('resources.i18n', 'locale'), 'pt_BR')
        self.assertEqual(config.get_or_load('resources.i18n', 'timezone'), 'America/Sao_Paulo')
示例#5
0
 def test_get_with_default_and_module_load(self):
     config = Config()
     self.assertEqual(config.get_or_load('resources.i18n', 'locale'), 'en_US')
     self.assertEqual(config.get_or_load('resources.i18n', 'locale', 'foo'), 'en_US')
示例#6
0
    def test_get_with_default_and_none(self):
        config = Config({'foo': {
            'bar': None,
        }})

        self.assertEqual(config.get_or_load('foo', 'bar', 'ooops'), None)
示例#7
0
    def test_get_with_default(self):
        config = Config()

        self.assertEqual(config.get_or_load('resources.i18n', 'bar', 'baz'), 'baz')
示例#8
0
    def test_get(self):
        config = Config({'foo': {
            'bar': 'baz',
        }})

        self.assertEqual(config.get_or_load('foo', 'bar'), 'baz')