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_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_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 save(config_obj, full_file_path): '''Save an instance of Config (config_obj) to full_file_path''' config_data = config_obj.as_dict() return config_file.save(config_data, full_file_path)