예제 #1
0
def test_jinja2_large_template_str(output):
    tmpl = TemplateEngine.get('jinja2')
    result = tmpl.expand('hello {{hello}}' * 15000, sample_dict)
    assert result.startswith('hello world')

    log = '\n'.join(c[0][0].strip() for c in output.call_args_list)

    assert """\
ERROR: You are trying to render a template that is bigger than 100KiB we've \
seen that Jinja can crash at large templates and suggest you find \
alternatives for this. The affected template starts with:
hello {{hello}}hello {{hello}}hello {{hello}}hello {{hello}}hello \
{{hello}}hello {{hello}}hello {{he""" == log
예제 #2
0
def test_jinja2_umlaut_variables():
    tmpl = TemplateEngine.get('jinja2')
    assert 'hello wörld' == tmpl.expand('hello {{hello2}}', sample_dict)
예제 #3
0
def test_jinja2_unknown_variable_should_fail():
    tmpl = TemplateEngine.get('jinja2')
    with pytest.raises(jinja2.UndefinedError):
        tmpl.expand('unknown variable {{foo}}', {})
예제 #4
0
def test_jinja2_template_file():
    tmpl = TemplateEngine.get('jinja2')
    filename = '{}/haproxy.cfg'.format(fixture)
    result = tmpl.template(filename + '.jinja2', sample_dict)
    with open(filename) as ref:
        assert ref.read() == result
예제 #5
0
def test_jinja2_template_keep_trailing_newline():
    tmpl = TemplateEngine.get('jinja2')
    assert ('hello world\n' == tmpl.expand('hello world\n', {}))
예제 #6
0
def test_jinja2_template_dont_add_trailing_newline():
    tmpl = TemplateEngine.get('jinja2')
    assert ('hello world' == tmpl.expand('hello world', {}))
예제 #7
0
def test_abstract_engine():
    engine = TemplateEngine()
    with pytest.raises(NotImplementedError):
        engine._render_template_file("asdf", {})
    with pytest.raises(NotImplementedError):
        engine.expand("asdf", {})
예제 #8
0
def test_jinja2_template_str():
    tmpl = TemplateEngine.get('jinja2')
    assert 'hello world' == tmpl.expand('hello {{hello}}', sample_dict)
    assert ('hello world\n\n   ' == tmpl.expand('hello {{hello}}\n\n   ',
                                                sample_dict))
예제 #9
0
def test_unknown_template_engine():
    with pytest.raises(NotImplementedError):
        TemplateEngine.get('foo')
예제 #10
0
파일: test_template.py 프로젝트: wosc/batou
def test_jinja2_umlaut_variables():
    tmpl = TemplateEngine.get("jinja2")
    assert "hello wörld" == tmpl.expand("hello {{hello2}}", sample_dict)
예제 #11
0
파일: test_template.py 프로젝트: wosc/batou
def test_jinja2_template_dont_add_trailing_newline():
    tmpl = TemplateEngine.get("jinja2")
    assert "hello world" == tmpl.expand("hello world", {})
예제 #12
0
파일: test_template.py 프로젝트: wosc/batou
def test_jinja2_template_keep_trailing_newline():
    tmpl = TemplateEngine.get("jinja2")
    assert "hello world\n" == tmpl.expand("hello world\n", {})
예제 #13
0
파일: test_template.py 프로젝트: wosc/batou
def test_jinja2_template_str():
    tmpl = TemplateEngine.get("jinja2")
    assert "hello world" == tmpl.expand("hello {{hello}}", sample_dict)
    assert "hello world\n\n   " == tmpl.expand("hello {{hello}}\n\n   ",
                                               sample_dict)