def test_configuration_rendering(tmpdir): source = os.path.join(get_edi_plugin_directory(), 'config_templates', 'project_tree') assert os.path.isdir(source) assert not os.listdir(str(tmpdir)) # target should be empty copy_tree(source, str(tmpdir)) template_link = os.path.join(str(tmpdir), 'PROJECTNAME-develop.yml.edilink') assert os.path.isfile(template_link) template = ConfigurationTemplate(str(tmpdir)) result = template.render({'edi_project_name': 'test-project'}) assert 'PROJECTNAME' not in ''.join(result) assert 'plugins/playbooks/sample_playbook/roles/sample_role/tasks/main.yml' in ''.join( result) assert not os.path.isfile(template_link) test_project_dev = os.path.join(str(tmpdir), 'test-project-develop.yml') assert os.path.isfile(test_project_dev) assert os.path.islink(test_project_dev) gitignore = os.path.join(str(tmpdir), '.gitignore') assert os.path.isfile(gitignore) with open(test_project_dev, mode='r', encoding='UTF-8') as config_file: cp = ConfigurationParser(config_file) assert cp.get_bootstrap_architecture() == 'amd64'
def run(self, project_name, config_template): workdir = os.getcwd() if os.getuid() == 0: raise FatalError('Do not initialize a configuration as root!') if not os.access(workdir, os.W_OK): raise FatalError('''No write access to '{}'.'''.format(workdir)) if os.listdir(workdir): raise FatalError( 'Please initialize your new configuration within an empty folder!' ) source = get_project_tree() copy_tree(source, workdir) template = ConfigurationTemplate(workdir) with open(get_template(config_template), encoding="UTF-8", mode="r") as template_file: t = Template(template_file.read()) template_dict = yaml.load(t.render(get_base_dictionary())).get( 'parameters', {}) template_dict['edi_project_name'] = project_name template_dict["edi_edi_version"] = get_stripped_version( get_edi_version()) template.render(template_dict) print_success( '''Configuration for project '{}' generated in folder '{}'.'''. format(project_name, workdir))
def datadir(tmpdir, request): ''' Move data from tests/data/TESTNAME into a temporary directory so that the test can modify its data set. ''' test_subdir = os.path.basename(os.path.splitext(request.module.__file__)[0]) test_data = os.path.abspath(os.path.join(os.path.dirname(__file__), 'data', test_subdir)) if os.path.isdir(test_data): copy_tree(str(test_data), str(tmpdir)) return tmpdir