def action_create(self): with Environment.get_instance_copy() as env: repo_file_name = self.resource.repo_file_name repo_dir = repos_dirs[env.system.os_family] repo_template = self.resource.repo_template new_content = Template(repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name, base_url=self.resource.base_url, mirror_list=self.resource.mirror_list) repo_file_path = format("{repo_dir}/{repo_file_name}.repo") if self.resource.append_to_file and os.path.isfile(repo_file_path): with open(repo_file_path, 'a') as repo_file: repo_file.write('\n' + new_content.get_content()) else: File(repo_file_path, content=new_content)
def action_create(self): with Environment.get_instance_copy() as env: repo_file_name = self.resource.repo_file_name repo_dir = repos_dirs[env.system.os_family] repo_template = self.resource.repo_template new_content = Template( repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name, base_url=self.resource.base_url, mirror_list=self.resource.mirror_list, ) repo_file_path = format("{repo_dir}/{repo_file_name}.repo") if self.resource.append_to_file and os.path.isfile(repo_file_path): with open(repo_file_path, "a") as repo_file: repo_file.write("\n" + new_content.get_content()) else: File(repo_file_path, content=new_content)
def action_create(self): with Environment.get_instance_copy() as env: repo_file_name = self.resource.repo_file_name repo_dir = get_repo_dir() repo_template = os.path.join( os.path.dirname(os.path.realpath(__file__)), '..', REPO_TEMPLATE_FOLDER, self.resource.repo_template) new_content = Template(repo_template, repo_id=self.resource.repo_id, repo_file_name=self.resource.repo_file_name, base_url=self.resource.base_url, mirror_list=self.resource.mirror_list) repo_file_path = format("{repo_dir}/{repo_file_name}.repo") if self.resource.append_to_file and os.path.isfile(repo_file_path): with open(repo_file_path, 'a') as repo_file: repo_file.write('\n' + new_content.get_content()) else: File(repo_file_path, content=new_content)
def test_template_loader_arguments(self, exists_mock, getmtime_mock, open_mock): """ Testing template loader additional arguments in template and absolute file-path """ exists_mock.return_value = True getmtime_mock.return_value = 10 file_mock = MagicMock(name = 'file_mock') file_mock.__enter__.return_value = file_mock file_mock.read.return_value = '{{test_arg1}} template content' open_mock.return_value = file_mock with Environment("/base") as env: template = Template("/absolute/path/test.j2", [], test_arg1 = "test") content = template.get_content() self.assertEqual(open_mock.call_count, 1) self.assertEqual(u'test template content\n', content) open_mock.assert_called_with('/absolute/path/test.j2', 'rb') self.assertEqual(getmtime_mock.call_count, 1) getmtime_mock.assert_called_with('/absolute/path/test.j2')
def test_template_loader_arguments(self, exists_mock, getmtime_mock, open_mock): """ Testing template loader additional arguments in template and absolute file-path """ exists_mock.return_value = True getmtime_mock.return_value = 10 file_mock = MagicMock(name = 'file_mock') file_mock.__enter__.return_value = file_mock file_mock.read.return_value = '{{test_arg1}} template content' open_mock.return_value = file_mock with Environment("/base") as env: template = Template("/absolute/path/test.j2", [], test_arg1 = "test") content = template.get_content() self.assertEqual(open_mock.call_count, 1) self.assertEqual(u'test template content', content) open_mock.assert_called_with('/absolute/path/test.j2', 'rb') self.assertEqual(getmtime_mock.call_count, 1) getmtime_mock.assert_called_with('/absolute/path/test.j2')