Beispiel #1
0
 def test_defaults(self):
     self.assertEquals(
         envtpl._render_string('{{ FOO | default("abc") }}', {},
                               jinja2.StrictUndefined), 'abc')
     self.assertEquals(
         envtpl._render_string('{{ FOO | default("abc") }}', {'FOO': 'def'},
                               jinja2.StrictUndefined), 'def')
Beispiel #2
0
    def test_unicode_input(self):
        string = u'''
åäö
'''
        expected = u'''
åäö
'''
        self.assertEquals(envtpl._render_string(string, {}, jinja2.StrictUndefined), expected)
Beispiel #3
0
    def test_unicode_input(self):
        string = u'''
åäö
'''
        expected = u'''
åäö
'''
        self.assertEquals(envtpl._render_string(string, {}, jinja2.StrictUndefined), expected)
Beispiel #4
0
    def test_environment_prefix(self):
        string = '''
{% for key, value in environment('X_') %}{{ key }} = {{ value }}
{% endfor %}
'''
        expected = '''
foo = bar
'''
        self.assertEquals(envtpl._render_string(string, {'X_foo': 'bar', 'baz': 'X_qux'}, jinja2.StrictUndefined), expected)
Beispiel #5
0
    def test_from_json_object(self):
        string = '''
{{ (FOO | from_json).bar }}
'''
        expected = '''
baz
'''
        self.assertEquals(envtpl._render_string(string, {'FOO': '{"bar": "baz"}'},
                                                jinja2.StrictUndefined, '{{,}}'), expected)
Beispiel #6
0
    def test_from_json_object(self):
        string = '''
{{ (FOO | from_json).bar }}
'''
        expected = '''
baz
'''
        self.assertEquals(envtpl._render_string(string, {'FOO': '{"bar": "baz"}'},
                                                jinja2.StrictUndefined), expected)
Beispiel #7
0
    def test_quoted(self):
        string = '''
foo = {{ FOO | default(123) }}
bar = "{{ BAR | default("abc") }}"
'''
        expected = '''
foo = 456
bar = "abc"
'''
        self.assertEquals(envtpl._render_string(string, {'FOO': 456}, jinja2.StrictUndefined), expected)
Beispiel #8
0
    def test_environment_prefix(self):
        string = '''
{% for key, value in environment('X_') %}{{ key }} = {{ value }}
{% endfor %}
'''
        expected = '''
foo = bar
'''
        self.assertEquals(envtpl._render_string(string, {'X_foo': 'bar', 'baz': 'X_qux'},
                          jinja2.StrictUndefined, '{{,}}'), expected)
Beispiel #9
0
    def test_quoted(self):
        string = '''
foo = {{ FOO | default(123) }}
bar = "{{ BAR | default("abc") }}"
'''
        expected = '''
foo = 456
bar = "abc"
'''
        self.assertEquals(envtpl._render_string(string, {'FOO': 456},
                          jinja2.StrictUndefined, '{{,}}'), expected)
Beispiel #10
0
    def test_environment(self):
        string = '''
{% for key, value in environment() %}{{ key }} = {{ value }}
{% endfor %}
'''
        expected = '''
baz = qux
foo = bar
'''
        self.assertEquals(envtpl._render_string(string, {'foo': 'bar', 'baz': 'qux'},
                          jinja2.StrictUndefined), expected)
Beispiel #11
0
    def test_from_json_list(self):
        string = '''
{% for foo in FOOS_JSON | from_json %}{{ foo.bar }}
{% endfor %}
'''
        expected = '''
hello
world
'''
        foos_json = '[{"bar": "hello"}, {"bar": "world"}]'
        self.assertEquals(envtpl._render_string(string, {'FOOS_JSON': foos_json},
                                                jinja2.StrictUndefined), expected)
Beispiel #12
0
    def test_from_json_list(self):
        string = '''
{% for foo in FOOS_JSON | from_json %}{{ foo.bar }}
{% endfor %}
'''
        expected = '''
hello
world
'''
        foos_json = '[{"bar": "hello"}, {"bar": "world"}]'
        self.assertEquals(envtpl._render_string(string, {'FOOS_JSON': foos_json},
                                                jinja2.StrictUndefined, '{{,}}'), expected)
Beispiel #13
0
    def test_if_block(self):
        string = '''
{% if BAZ is defined %}
foo = 123
{% else %}
foo = 456
{% endif %}
bar = "abc"'''
        expected = '''

foo = 456

bar = "abc"'''
        self.assertEquals(envtpl._render_string(string, {}, jinja2.StrictUndefined), expected)
Beispiel #14
0
    def test_if_block(self):
        string = '''
{% if BAZ is defined %}
foo = 123
{% else %}
foo = 456
{% endif %}
bar = "abc"'''
        expected = '''

foo = 456

bar = "abc"'''
        self.assertEquals(envtpl._render_string(string, {}, jinja2.StrictUndefined), expected)
Beispiel #15
0
 def test_defaults(self):
     self.assertEquals(envtpl._render_string('{{ FOO | default("abc") }}', {},
                       jinja2.StrictUndefined), 'abc')
     self.assertEquals(envtpl._render_string('{{ FOO | default("abc") }}', {'FOO': 'def'},
                       jinja2.StrictUndefined), 'def')
Beispiel #16
0
 def test_dont_die_on_missing(self):
     self.assertEquals(envtpl._render_string('{{ FOO }}', {}, jinja2.Undefined), '')
Beispiel #17
0
 def test_empty(self):
     self.assertEquals(envtpl._render_string('', {}, jinja2.StrictUndefined), '')
Beispiel #18
0
 def test_uuid(self):
     string = '''{{ "echo foo"|uuid }}'''
     uuid = envtpl._render_string(string, {}, jinja2.StrictUndefined)
     self.assertEquals(len(uuid), 32)
Beispiel #19
0
 def test_dont_die_on_missing(self):
     self.assertEquals(envtpl._render_string('{{ FOO }}', {}, jinja2.Undefined, '{{,}}'), '')
Beispiel #20
0
 def test_empty(self):
     self.assertEquals(envtpl._render_string('', {}, jinja2.StrictUndefined, '{{,}}'), '')
Beispiel #21
0
    def test_custom_var_delimiters(self):
        string = '{{ FOO }} [[ BAR ]]'
        expected = '{{ FOO }} baz'

        self.assertEquals(envtpl._render_string(string, {'BAR': 'baz'}, jinja2.StrictUndefined,
                          '[[,]]'), expected)
Beispiel #22
0
 def test_shell(self):
     string = '''{{ "echo foo"|shell }}'''
     self.assertEquals(
         envtpl._render_string(string, {}, jinja2.StrictUndefined), "foo\n")