def test_test_environment_context(): from jinja2 import FileSystemLoader templates_path = fixture_path('templates') with temp_template_environment(templates_path): env = environment() env.get_template('tests/test_template.sh.jinja') env = environment() template = env.get_template('init/activate.sh.jinja')
def test_project_command_renders_template(FakeProject): """Test that a project command adds current project to the context""" (FakeProject.expects('load') .with_args('options').returns('proj')) with temp_template_environment(fixture_path('templates')): class FakeCommand(NoEventProjectCommand): name = 'test' def run(self, project, options, **kwargs): assert self.render_template_string('{{project}}') == 'proj' assert self.render_template( 'tests/test_project_template.sh.tmpl').strip() == 'proj' command = FakeCommand() assert command.execute(None, 'options', test='test') == 0
def test_command_renders_template(): """Test that command renders a template file""" with temp_template_environment(fixture_path('templates')): class FakeCommand(NoEventCommand): name = 'test' def run(self, *args, **kwargs): self.called = True # Test with the default context assert self.render_template( 'tests/test_template.sh.tmpl').strip() == 'test::options' # Test with a user defined context assert self.render_template( 'tests/test_with_context.sh.tmpl', testvalue='bar').strip() == 'bar' command = FakeCommand() return_code = command.execute(None, 'options') assert return_code == 0 assert_called_flag(command)
def test_command_renders_template_string(): """Test that command renders a template string""" with temp_template_environment(fixture_path('templates')): class FakeCommand(NoEventCommand): name = 'test' def run(self, *args, **kwargs): self.called = True assert self.render_template_string( '{{command.name}}') == 'test' assert self.render_template_string( '{{options}}') == 'options' # Test with a user defined context assert self.render_template_string( '{{testvalue}}', testvalue='foo') == 'foo' command = FakeCommand() return_code = command.execute(None, 'options') assert return_code == 0 assert_called_flag(command)