Ticket #2016: 0004-Adds-tests-for-object_tag.diff

File 0004-Adds-tests-for-object_tag.diff, 2.1 KB (added by marcusf, 5 years ago)
  • new file tests/regressiontests/templates/object_tag.py

    diff --git a/tests/regressiontests/templates/object_tag.py b/tests/regressiontests/templates/object_tag.py
    new file mode 100644
    index 0000000..5f67b9e
    - +  
     1object_tag_tests = """
     2>>> t = template.Template('{% load custom %}{% get_meaning_of_life as answer %}{{ answer }}')
     3>>> t.render(template.Context())
     4u"42"
     5>>> t = template.Template('{% load custom %}{% get_mascot_with "awesomeness" "magical powers" as pony %}{{ pony }}')
     6>>> t.render(template.Context())
     7u"This mascot is filled with awesomeness and magical powers"
     8>>> t = template.Template('{% load custom %}{% count "e" word as num %}{{ num }}')
     9>>> t.render(template.Context({'word': 'beefcake'}))
     10u"3"
     11"""
  • tests/regressiontests/templates/templatetags/custom.py

    diff --git a/tests/regressiontests/templates/templatetags/custom.py b/tests/regressiontests/templates/templatetags/custom.py
    index fdf8d10..bbb8c08 100644
    a b trim = stringfilter(trim) 
    99
    1010register.filter(trim)
    1111
     12def get_meaning_of_life():
     13    return 42
     14register.object_tag(get_meaning_of_life)
     15
     16def get_mascot_with(power_one, power_two):
     17    return 'This mascot is filled with %s and %s' % (power_one, power_two)
     18register.object_tag(get_mascot_with)
     19
     20def count(char, word):
     21    return word.count(char)
     22register.object_tag(count)
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index 9c01b49..0badc86 100644
    a b from context import context_tests 
    2424from custom import custom_filters
    2525from parser import filter_parsing, variable_parsing
    2626from unicode import unicode_tests
     27from object_tag import object_tag_tests
    2728
    2829try:
    2930    from loaders import *
    __test__ = { 
    3839    'context': context_tests,
    3940    'filter_parsing': filter_parsing,
    4041    'custom_filters': custom_filters,
     42    'object_tag': object_tag_tests,
    4143}
    4244
    4345#################################
Back to Top