Beispiel #1
0
def test_save_config_to_readonly_file_with_logger(*args, **kwargs):
    with tempfile.NamedTemporaryFile() as tmpfile:
        environ = {'COFFER_CONFIG': tmpfile.name}
        with mock.patch('os.environ', environ):
            cfg = config.load_config()
    assert_config_equals(cfg, config._defaults)

    cfg.add_section('test')
    cfg.set('test', 'test', 'test')

    with tempfile.NamedTemporaryFile() as tmpfile:
        os.chmod(tmpfile.name, ~(stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH))
        environ = {'COFFER_CONFIG': tmpfile.name}
        with mock.patch('os.environ', environ):
            config.save_config(cfg, logger=LoggerDecoy())
            loaded_cfg = config.load_config()
    assert_config_equals(loaded_cfg, config._defaults)
Beispiel #2
0
def test_save_config_to_non_existent_file(*args, **kwargs):
    with tempfile.NamedTemporaryFile() as tmpfile:
        environ = {'COFFER_CONFIG': tmpfile.name}
        with mock.patch('os.environ', environ):
            cfg = config.load_config()
    assert_config_equals(cfg, config._defaults)

    cfg.add_section('test')
    cfg.set('test', 'test', 'test')

    with tempfile.NamedTemporaryFile() as tmpfile:
        filename = tmpfile.name
    ok_(not os.path.exists(filename), '{} exists'.format(filename))

    environ = {'COFFER_CONFIG': filename}
    with mock.patch('os.environ', environ):
        config.save_config(cfg)
        loaded_cfg = config.load_config()
    assert_config_equals(loaded_cfg, config._defaults)
Beispiel #3
0
def test_save_config_with_modifications(*args, **kwargs):
    with tempfile.NamedTemporaryFile() as tmpfile:
        environ = {'COFFER_CONFIG': tmpfile.name}
        with mock.patch('os.environ', environ):
            cfg = config.load_config()
    assert_config_equals(cfg, config._defaults)

    cfg.add_section('test')
    cfg.set('test', 'test', 'test')

    with tempfile.NamedTemporaryFile() as tmpfile:
        environ = {'COFFER_CONFIG': tmpfile.name}
        with mock.patch('os.environ', environ):
            config.save_config(cfg)
            loaded_cfg = config.load_config()

    new_dict = {'test': {'test': 'test'}}
    new_dict.update(config._defaults)
    assert_config_equals(loaded_cfg, new_dict)