forked from moraes/tipfy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_test.py
31 lines (22 loc) · 1013 Bytes
/
template_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import unittest
from tipfy import template
import test_utils
TEMPLATES_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
'resources', 'templates'))
TEMPLATES_ZIP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__),
'resources', 'templates.zip'))
class TestTemplate(test_utils.BaseTestCase):
def test_generate(self):
t = template.Template('<html>{{ myvalue }}</html>')
self.assertEqual(t.generate(myvalue='XXX'), '<html>XXX</html>')
def test_loader(self):
loader = template.Loader(TEMPLATES_DIR)
t = loader.load('template_tornado1.html')
self.assertEqual(t.generate(students=['calvin', 'hobbes', 'moe']), '\n\ncalvin\n\n\n\nhobbes\n\n\n\nmoe\n\n\n')
def test_loader2(self):
loader = template.ZipLoader(TEMPLATES_ZIP_DIR, 'templates')
t = loader.load('template1.html')
self.assertEqual(t.generate(message='Hello, World!'), 'Hello, World!\n')
if __name__ == '__main__':
test_utils.main()