Exemplo n.º 1
0
    def test_get_existing_keys_from_default(self):
        config = Config({}, {'foo': {
            'bar': 'baz',
            'doo': 'ding',
        }})

        self.assertEqual(config.get_config('foo', 'bar'), 'baz')
        self.assertEqual(config.get_config('foo', 'doo'), 'ding')
Exemplo n.º 2
0
    def test_get_existing_keys_from_default(self):
        config = Config({}, {'foo': {
            'bar': 'baz',
            'doo': 'ding',
        }})

        assert config.get('foo', 'bar') == 'baz'
        assert config.get('foo', 'doo') == 'ding'
Exemplo n.º 3
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

        assert config.get_or_load('resources.template', 'templates_dir') == template_config['templates_dir']
        assert config.get_or_load('resources.i18n', 'locale') == i18n_config['locale']
        assert config.get_or_load('resources.i18n', 'timezone') == i18n_config['timezone']
Exemplo n.º 4
0
    def test_override_config2(self):
        config = Config({
            'resources.i18n': {
                'timezone': 'America/Sao_Paulo',
            },
        })

        self.assertEqual(config.get_config('resources.i18n', 'locale'), 'en_US')
        self.assertEqual(config.get_config('resources.i18n', 'timezone'), 'America/Sao_Paulo')
Exemplo n.º 5
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_config('resources.template', 'templates_dir'), template_config['templates_dir'])
        self.assertEqual(config.get_config('resources.i18n', 'locale'), i18n_config['locale'])
        self.assertEqual(config.get_config('resources.i18n', 'timezone'), i18n_config['timezone'])
Exemplo n.º 6
0
    def test_override_config2(self):
        config = Config({
            'resources.i18n': {
                'timezone': 'America/Sao_Paulo',
            },
        })

        assert config.get_or_load('resources.i18n', 'locale') == 'en_US'
        assert config.get_or_load('resources.i18n', 'timezone') == 'America/Sao_Paulo'
Exemplo n.º 7
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.
        assert 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.
        assert config.get_or_load('resources.i18n', 'i_dont_exist', 'foo') == 'foo'
Exemplo n.º 8
0
    def test_get_dict_existing_keys(self):
        config = Config({'foo': {
            'bar': 'baz',
            'doo': 'ding',
        }})

        self.assertEqual(config.get_config('foo'), {
            'bar': 'baz',
            'doo': 'ding',
        })
Exemplo n.º 9
0
    def test_get_dict_existing_keys(self):
        config = Config({'foo': {
            'bar': 'baz',
            'doo': 'ding',
        }})

        assert config.get('foo') == {
            'bar': 'baz',
            'doo': 'ding',
        }
Exemplo n.º 10
0
    def test_setdefault(self):
        config = Config()

        self.assertRaises(KeyError, config.get_config, 'foo')

        config.setdefault('foo', {
            'bar': 'baz',
            'doo': 'ding',
        })

        self.assertEqual(config.get_config('foo', 'bar'), 'baz')
        self.assertEqual(config.get_config('foo', 'doo'), 'ding')
Exemplo n.º 11
0
    def test_setdefault(self):
        config = Config()

        assert config.get('foo') is None

        config.setdefault('foo', {
            'bar': 'baz',
            'doo': 'ding',
        })

        assert config.get('foo', 'bar') == 'baz'
        assert config.get('foo', 'doo') == 'ding'
Exemplo n.º 12
0
    def test_get(self):
        config = Config({'foo': {
            'bar': 'baz',
            'doo': 'ding',
        }})

        self.assertEqual(config.get('foo'), {
            'bar': 'baz',
            'doo': 'ding',
        })

        self.assertEqual(config.get('bar'), {})
Exemplo n.º 13
0
    def test_update(self):
        config = Config({'foo': {
            'bar': 'baz',
            'doo': 'ding',
        }})

        self.assertEqual(config.get_config('foo', 'bar'), 'baz')
        self.assertEqual(config.get_config('foo', 'doo'), 'ding')

        config.update('foo', {'bar': 'other'})

        self.assertEqual(config.get_config('foo', 'bar'), 'other')
        self.assertEqual(config.get_config('foo', 'doo'), 'ding')
Exemplo n.º 14
0
    def test_update(self):
        config = Config({'foo': {
            'bar': 'baz',
            'doo': 'ding',
        }})

        assert config.get('foo', 'bar') == 'baz'
        assert config.get('foo', 'doo') == 'ding'

        config.update('foo', {'bar': 'other'})

        assert config.get('foo', 'bar') == 'other'
        assert config.get('foo', 'doo') == 'ding'
Exemplo n.º 15
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_config('resources.template', 'templates_dir'), 'apps/templates')
        self.assertEqual(config.get_config('resources.i18n', 'locale'), 'pt_BR')
        self.assertEqual(config.get_config('resources.i18n', 'timezone'), 'America/Sao_Paulo')
Exemplo n.º 16
0
    def test_override_config(self):
        config = Config({
            'resources.template': {
                'templates_dir': 'apps/templates'
            },
            'resources.i18n': {
                'locale': 'pt_BR',
                'timezone': 'America/Sao_Paulo',
            },
        })

        assert config.get_or_load('resources.template', 'templates_dir') == 'apps/templates'
        assert config.get_or_load('resources.i18n', 'locale') == 'pt_BR'
        assert config.get_or_load('resources.i18n', 'timezone') == 'America/Sao_Paulo'
Exemplo n.º 17
0
    def test_setdefault2(self):
        config = Config({'foo': {
            'bar': 'baz',
        }})

        assert config.get('foo') == {
            'bar': 'baz',
        }

        config.setdefault('foo', {
            'bar': 'wooo',
            'doo': 'ding',
        })

        assert config.get('foo', 'bar') == 'baz'
        assert config.get('foo', 'doo') == 'ding'
Exemplo n.º 18
0
    def test_setdefault2(self):
        config = Config({'foo': {
            'bar': 'baz',
        }})

        self.assertEqual(config.get_config('foo'), {
            'bar': 'baz',
        })

        config.setdefault('foo', {
            'bar': 'wooo',
            'doo': 'ding',
        })

        self.assertEqual(config.get_config('foo', 'bar'), 'baz')
        self.assertEqual(config.get_config('foo', 'doo'), 'ding')
Exemplo n.º 19
0
    def test_get(self):
        config = Config({'foo': {
            'bar': 'baz',
        }})

        assert config.get_or_load('foo', 'bar') == 'baz'
Exemplo n.º 20
0
    def test_get_with_default_and_none(self):
        config = Config({'foo': {
            'bar': None,
        }})

        self.assertEqual(config.get_config('foo', 'bar', 'ooops'), None)
Exemplo n.º 21
0
 def test_get_with_default_and_module_load(self):
     config = Config()
     self.assertEqual(config.get_config('resources.i18n', 'locale'), 'en_US')
     self.assertEqual(config.get_config('resources.i18n', 'locale', 'foo'), 'en_US')
Exemplo n.º 22
0
    def test_get_with_default(self):
        config = Config()

        assert config.get('foo', 'bar', 'ooops') == 'ooops'
        assert config.get('foo', 'doo', 'wooo') == 'wooo'
Exemplo n.º 23
0
    def test_get_with_default_and_none(self):
        config = Config({'foo': {
            'bar': None,
        }})

        assert config.get('foo', 'bar', 'ooops') is None
Exemplo n.º 24
0
    def test_get_with_default(self):
        config = Config()

        assert config.get_or_load('resources.i18n', 'bar', 'baz') == 'baz'
Exemplo n.º 25
0
    def test_get_dict_non_existing_keys(self):
        config = Config()

        assert config.get('bar') is None
Exemplo n.º 26
0
 def test_missing_default_config(self):
     config = Config()
     assert config.get_or_load('webapp2', 'foo') == 'baz'
Exemplo n.º 27
0
 def test_missing_key(self):
     config = Config()
     config.get_or_load('resources.i18n', 'i_dont_exist')
Exemplo n.º 28
0
 def test_missing_module2(self):
     config = Config()
     assert config.get_or_load('i_dont_exist') == 'baz'
Exemplo n.º 29
0
 def test_required_config(self):
     config = Config()
     config.get_or_load('resources.i18n', 'required')
Exemplo n.º 30
0
 def test_get_with_default_and_module_load(self):
     config = Config()
     assert config.get_or_load('resources.i18n', 'locale') == 'en_US'
     assert config.get_or_load('resources.i18n', 'locale', 'foo') == 'en_US'