1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Helpers for templatetags' unit tests in Django webframework
18 """
19
20 __id__ = __revision__ = "$Id: helpers.py 76 2007-02-27 15:38:53Z the.pythy $"
21 __url__ = "$URL: https://pythy.googlecode.com/svn/trunk/pytils/pytils/test/templatetags/helpers.py $"
22
23 from django.conf import settings
24
25 settings.configure(
26 TEMPLATE_DIRS=(),
27 TEMPLATE_CONTEXT_PROCESSORS=(),
28 TEMPLATE_LOADERS=(),
29 INSTALLED_APPS=('pytils',),
30 )
31
32 from django import template
33 from django.template import loader
34
35 import unittest
36
37
39 """
40 TestCase for testing template tags and filters
41 """
43 """
44 Method validates output of template tag or filter
45
46 @param template_name: name of template
47 @type template_name: C{str}
48
49 @param template_string: contents of template
50 @type template_string: C{str}
51
52 @param context: rendering context
53 @type context: C{dict}
54
55 @param result_string: reference output
56 @type result_string: C{str}
57 """
58
59 def test_template_loader(template_name, template_dirs=None):
60 return template_string, template_name
61
62 loader.template_source_loaders = [test_template_loader,]
63
64 output = loader.get_template(template_name).render(template.Context(context))
65
66 self.assertEquals(output, result_string)
67