Ejemplo n.º 1
0
def test_config_as_dict_empty():
    config_ = config.Config()
    config_data = config_.as_dict()

    assert isinstance(config_data, dict)

    assert set(config_data) == set(CONFIG_SECTIONS)
Ejemplo n.º 2
0
def test_save_empty_config():
    yaml_fo = tempfile.NamedTemporaryFile()

    _config = config.Config()

    res = config_file.save(_config.as_dict(), yaml_fo.name)

    log.debug('res: %s', res)
Ejemplo n.º 3
0
def test_config_init():
    config_ = config.Config()

    assert_object(config_)

    assert config_.server == {}
    assert config_.collections_path is None
    assert config_.global_collections_path is None
Ejemplo n.º 4
0
def test_config_unknown_attr():
    config_ = config.Config()

    assert hasattr(config_, 'not_a_valid_attr') is False
    try:
        blip = config_.not_a_valid_attr
    except AttributeError as e:
        log.debug(e, exc_info=True)
        return

    assert False, 'Expected to get an AttributeError accessing an unknown attr but did not and %s was returned' % blip
Ejemplo n.º 5
0
def test_save_config():
    yaml_fo = tempfile.NamedTemporaryFile()

    _config = config.Config()

    config.server = {
        'url': 'https://someserver.example.com',
        'ignore_certs': True
    }
    config.content_path = '~/.ansible/not-content-path'

    res = config_file.save(_config.as_dict(), yaml_fo.name)

    log.debug('res: %s', res)
Ejemplo n.º 6
0
def test_save_empty():
    yaml_fo = tempfile.NamedTemporaryFile()

    config_ = config.Config()

    config.save(config_, yaml_fo.name)

    res_fo = open(yaml_fo.name, 'r')

    written_yaml = res_fo.read()
    log.debug('written_yaml: %s', written_yaml)

    assert written_yaml != ''
    assert 'server' in written_yaml
    assert 'collections_path' in written_yaml
Ejemplo n.º 7
0
def test_save_bogus_path():
    _config = config.Config()

    config.server = {
        'url': 'https://someserver.example.com',
        'ignore_certs': True
    }
    config.content_path = '~/.ansible/not-content-path'

    bogus_path = '/dev/null/doesnt/exist.yml'
    res = None
    try:
        res = config_file.save(_config.as_dict(), bogus_path)
    except (OSError, IOError) as e:
        # at the moment, we expect this to raise an OSError or subclass, to
        # verify assert the filename match
        log.debug(e, exc_info=True)
        assert e.filename == bogus_path
        return

    assert res, 'Expected a OSError, IOError or subclass (NotADirectoryError etc) to be raised here'
Ejemplo n.º 8
0
def test_save():
    yaml_fo = tempfile.NamedTemporaryFile()

    config_ = config.Config()

    config_.options['some_option'] = 'some_option_value'

    config.save(config_, yaml_fo.name)

    res_fo = open(yaml_fo.name, 'r')

    written_yaml = res_fo.read()
    log.debug('written_yaml: %s', written_yaml)

    assert written_yaml != ''
    expected_strs = [
        'some_option',
        'some_option_value',
    ]
    for expected_str in expected_strs:
        assert expected_str in written_yaml, \
            'expected to find the string "%s" in written config file but did not. file contents: %s' % (expected_str, written_yaml)
Ejemplo n.º 9
0
def test_config_init():
    config_ = config.Config()

    assert_object(config_)