Esempio n. 1
0
 def testMultiargFilter(self):
     '''Test calling filter with multiply args'''
     multiarg_template = Template(name='multiarg-filter.html')
     multiarg_template.parse(
                         '{{ simple_var|multiarg_filter:"John" "Peter" }}')
     result = multiarg_template.execute({'simple_var': 'Hello'})
     self.assertResult(result, 'Hello, John, Peter')
Esempio n. 2
0
 def testMultiFilter(self):
     '''Test calling sequnce of filters'''
     multifilter_template = Template(name='multifilter.html')
     multifilter_template.parse(
                 '{{ simple_var|simple_filter|argument_filter:"world" }}')
     result = multifilter_template.execute({'simple_var': 'Hello'})
     self.assertResult(result, 'HELLO, world')
Esempio n. 3
0
 def setUp(self):
     self.value = 'value'
     self.variable_template = Template(name='base.html')
     self.variable_template.parse("{{ simple_var }}")
     self.object_field_template = Template(name='object-field.html')
     self.object_field_template.parse('{{ object.field }}')
     self.deep_template = Template(name='deep-field.html')
     self.deep_template.parse('{{ object.field.field }}')
Esempio n. 4
0
 def testSimpleIf(self):
     '''Test if template tag'''
     template = Template()
     template.parse('{% if a %}Foo{% endif %}')
     result = template({'a': 1})
     self.assertResult('if', result.strip(), 'Foo')
     result = template({'a': 0})
     self.assertResult('if', result.strip(), '')
Esempio n. 5
0
 def testVaribaleArgFilter(self):
     '''Test calling filter with variable argument'''
     varargfilter_template = Template(name='vararg-filter.html')
     varargfilter_template.parse('{{ simple_var|argument_filter:arg }}')
     result = varargfilter_template.execute({
             'simple_var': 'Hello',
             'arg': 'world'
     })
     self.assertResult(result, 'Hello, world')
Esempio n. 6
0
 def testSpacelless(self):
     '''Test spaceless template tag'''
     template = Template()
     template.parse('''{% spaceless %}
                     Some 
                         broken 
                 text
             {% endspaceless %}''')
     result = template({})
     right = 'Some broken text'
     assert result == right, 'Spaceless tag error:\n%s' % (
                                 "\n".join(result, 'except', right))
Esempio n. 7
0
class BlockTestCase(unittest.TestCase):
    """Test case for block template tag
    """

    def setUp(self):
        self.base_template = Template(name='base.html')
        self.base_template.parse(BASE)

    def testExecuteTemplate(self):
        '''Test base template execution'''
        result = self.base_template.execute({'title': 'Hello'})
        needed = BASE_RESULT % ('Hello')
        is_eq = fuzzy_equals(result, needed)
        assert is_eq, "Error template execution:\n%s" % (
                      "\n".join((result, "except", needed)))
Esempio n. 8
0
class ExtendTestCase(BlockTestCase):
    """Test case for extend template tag
    """

    def setUp(self):
        super(ExtendTestCase, self).setUp()
        self.extend_template = Template(loader=self.base_template.loader)
        self.extend_template.parse(EXTEND)

    def testExecuteTemplate(self):
        '''Test extending template execution'''
        result = self.extend_template.execute({'title': 'Hello'})
        needed = EXTEND_RESULT % ('Hello')
        is_eq = fuzzy_equals(result, needed)
        assert is_eq, "Error template execution:\n%s" % (
                      "\n".join((result, "except", needed)))
Esempio n. 9
0
class VariableFieldTestCase(unittest.TestCase):
    """Test case for block template tag
    """

    def setUp(self):
        self.value = 'value'
        self.variable_template = Template(name='base.html')
        self.variable_template.parse("{{ simple_var }}")
        self.object_field_template = Template(name='object-field.html')
        self.object_field_template.parse('{{ object.field }}')
        self.deep_template = Template(name='deep-field.html')
        self.deep_template.parse('{{ object.field.field }}')

    def assertResult(self, result):
        assert result == self.value, 'Error emplate execution: %s' % ' '.join((
                                     result, 'except', self.value))

    def testSimpleVariable(self):
        '''Test simple variable accessing from template'''
        result = self.variable_template.execute({'simple_var': 'value'})
        self.assertResult(result)

    def testObjectField(self):
        '''Test object's field accessing from template'''
        class TestClass(object):
            field = self.value
        result = self.object_field_template.execute({'object': TestClass()})
        self.assertResult(result)

    def testDictValue(self):
        '''Test dict item accessing from template'''
        obj = {'field': self.value}
        result = self.object_field_template.execute({'object': obj})
        self.assertResult(result)

    def testMultilevelField(self):
        '''Test accesing to dict item as object field'''
        class TestClass(object):
            field = {'field': self.value}
        result = self.deep_template.execute({'object': TestClass()})
        self.assertResult(result)
Esempio n. 10
0
 def setUp(self):
     super(ExtendTestCase, self).setUp()
     self.extend_template = Template(loader=self.base_template.loader)
     self.extend_template.parse(EXTEND)
Esempio n. 11
0
 def testArgFilter(self):
     '''Test calling template filter with arg value specified'''
     argument_template = Template(name='argument-filter.html')
     argument_template.parse('{{ simple_var|argument_filter:"world" }}')
     result = argument_template.execute({'simple_var': 'Hello'})
     self.assertResult(result, 'Hello, world')
Esempio n. 12
0
 def testNumericConstFilter(self):
     '''Test simple template filter function applied to number'''
     simple_template = Template(name="consts-filter.html")
     simple_template.parse('{{ 1|simple_filter }}')
     result = simple_template.execute({})
     self.assertResult(result, '1')
Esempio n. 13
0
 def testStringConstFilter(self):
     '''Test simple template filter function applied to string constant'''
     simple_template = Template(name="consts-filter.html")
     simple_template.parse('{{ "hello"|simple_filter }}')
     result = simple_template.execute({})
     self.assertResult(result, 'HELLO')
Esempio n. 14
0
 def testSimpleFilter(self):
     '''Test simple template filter function applied to variable'''
     simple_template = Template(name='simple-filter.html')
     simple_template.parse("{{ simple_var|simple_filter }}")
     result = simple_template.execute({'simple_var': 'Hello'})
     self.assertResult(result, 'HELLO')
Esempio n. 15
0
 def testSimpleFor(self):
     '''Test for template tag'''
     template = Template()
     template.parse('{% for a in list %}{{ a }} {% endfor %}')
     result = template({'list': [1, 2, 3, 4, 5]})
     self.assertResult('for', result.strip(), '1 2 3 4 5')
Esempio n. 16
0
 def setUp(self):
     self.base_template = Template(name='base.html')
     self.base_template.parse(BASE)
Esempio n. 17
0
 def testSimpleWith(self):
     '''Test with template tag'''
     template = Template()
     template.parse('{% with user.name as name %}{{ name }}{% endwith %}')
     result = template({'user': {'name': 'John'}})
     self.assertResult('with', result.strip(), 'John')
Esempio n. 18
0
 def setUp(self):
     base_template = Template(name="base")
     base_template.parse('{{ now }}{{ future }}')
     self.partial_template = base_template.partial({'now': 'Hello'}, 'part')