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)
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)
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
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
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)
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
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'
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)
def test_config_init(): config_ = config.Config() assert_object(config_)