Esempio n. 1
0
 def test_keyword_args(self):
     rendered = Template('{% call pow 2 e=5 %}').render(pow=pow)
     self.assertEquals(rendered, '32')
     rendered = Template('{% call pow e=4 %}').render(pow=pow)
     self.assertEquals(rendered, '16')
     rendered = Template('{% call pow m=3 e=4 %}').render(pow=pow)
     self.assertEquals(rendered, '81')
Esempio n. 2
0
 def test_truthy_thingy(self):
     rendered = Template('{% if items %}we have items{% end %}').render(
         items=[])
     self.assertEquals(rendered, '')
     rendered = Template('{% if items %}we have items{% end %}').render(
         items=None)
     self.assertEquals(rendered, '')
     rendered = Template('{% if items %}we have items{% end %}').render(
         items='')
     self.assertEquals(rendered, '')
     rendered = Template('{% if items %}we have items{% end %}').render(
         items=[1])
     self.assertEquals(rendered, 'we have items')
Esempio n. 3
0
 def test_each_parent_context(self):
     rendered = Template(
         '{% each [1, 2, 3] %}<div>{{..name}}-{{it}}</div>{% end %}'
     ).render(name='jon doe')
     self.assertEquals(
         rendered,
         '<div>jon doe-1</div><div>jon doe-2</div><div>jon doe-3</div>')
Esempio n. 4
0
def render_template(template_name, **kwargs):
    kwargs.update({"static": config["static"]})

    with open(os.path.join(config["templates"], template_name),
              'r',
              encoding='utf-8') as f:
        template_body = f.read()

    return Template(template_body).render(**kwargs)
Esempio n. 5
0
 def test_positional_args(self):
     rendered = Template('{% call pow 3 %}').render(pow=pow)
     self.assertEquals(rendered, '9')
     rendered = Template('{% call pow 2 3 %}').render(pow=pow)
     self.assertEquals(rendered, '8')
Esempio n. 6
0
 def test_no_args(self):
     rendered = Template('{% call pow %}').render(pow=pow)
     self.assertEquals(rendered, '4')
Esempio n. 7
0
 def test_nested_if(self):
     tmpl = '{% if num > 5 %}{% each [1, 2] %}{{it}}{% end %}{% else %}{% each [3, 4] %}{{it}}{% end %}{% end %}'
     rendered = Template(tmpl).render(num=6)
     self.assertEquals(rendered, '12')
     rendered = Template(tmpl).render(num=4)
     self.assertEquals(rendered, '34')
Esempio n. 8
0
 def test_if_else_else_branch(self):
     rendered = Template(
         '{% if num > 5 %}<div>more than 5</div>{% else %}<div>less or equal to 5</div>{% end %}'
     ).render(num=4)
     self.assertEquals(rendered, '<div>less or equal to 5</div>')
Esempio n. 9
0
 def test_simple_if_is_false(self):
     rendered = Template(
         '{% if num > 5 %}<div>more than 5</div>{% end %}').render(num=4)
     self.assertEquals(rendered, '')
Esempio n. 10
0
 def test_each_iterable_in_context(self):
     rendered = Template('{% each items %}<div>{{it}}</div>{% end %}'
                         ).render(items=['alex', 'maria'])
     self.assertEquals(rendered, '<div>alex</div><div>maria</div>')
Esempio n. 11
0
 def test_nested_tag(self):
     rendered = Template('{% each items %}{% if it %}yes{% end %}{% end %}'
                         ).render(items=['', None, '2'])
     self.assertEquals(rendered, 'yes')
Esempio n. 12
0
 def test_nested_objects(self):
     context = {'lines': [{'name': 'l1'}], 'name': 'p1'}
     rendered = Template(
         '<h1>{{name}}</h1>{% each lines %}<span class="{{..name}}-{{it.name}}">{{it.name}}</span>{% end %}'
     ).render(**context)
     self.assertEquals(rendered, '<h1>p1</h1><span class="p1-l1">l1</span>')
Esempio n. 13
0
 def test_each_no_tags_inside(self):
     rendered = Template('{% each [1,2,3] %}<br>{% end %}').render()
     self.assertEquals(rendered, '<br><br><br>')
Esempio n. 14
0
 def test_each_space_issues(self):
     rendered = Template(
         '{% each [1,2, 3]%}<div>{{it}}</div>{%end%}').render()
     self.assertEquals(rendered, '<div>1</div><div>2</div><div>3</div>')
Esempio n. 15
0
 def test_each_iterable_as_literal_list(self):
     rendered = Template(
         '{% each [1, 2, 3] %}<div>{{it}}</div>{% end %}').render()
     self.assertEquals(rendered, '<div>1</div><div>2</div><div>3</div>')