Skip to content

Commit 6b18aff

Browse files
author
Richard Jones
committed
New tests for htmltemplate (well, it's a beginning)
1 parent cdc3bd7 commit 6b18aff

File tree

2 files changed

+127
-2
lines changed

2 files changed

+127
-2
lines changed

test/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: __init__.py,v 1.12 2002-01-14 06:53:28 richard Exp $
18+
# $Id: __init__.py,v 1.13 2002-01-21 11:05:48 richard Exp $
1919

2020
import unittest
2121
import os, tempfile
2222
os.environ['SENDMAILDEBUG'] = tempfile.mktemp()
2323

2424
import test_dates, test_schema, test_db, test_multipart, test_mailsplit
25-
import test_init, test_token, test_mailgw
25+
import test_init, test_token, test_mailgw, test_htmltemplate
2626

2727
def go():
2828
suite = unittest.TestSuite((
@@ -34,13 +34,17 @@ def go():
3434
test_mailsplit.suite(),
3535
test_mailgw.suite(),
3636
test_token.suite(),
37+
test_htmltemplate.suite(),
3738
))
3839
runner = unittest.TextTestRunner()
3940
result = runner.run(suite)
4041
return result.wasSuccessful()
4142

4243
#
4344
# $Log: not supported by cvs2svn $
45+
# Revision 1.12 2002/01/14 06:53:28 richard
46+
# had commented out some tests
47+
#
4448
# Revision 1.11 2002/01/14 02:20:15 richard
4549
# . changed all config accesses so they access either the instance or the
4650
# config attriubute on the db. This means that all config is obtained from

test/test_htmltemplate.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#
2+
# Copyright (c) 2001 Richard Jones
3+
# This module is free software, and you may redistribute it and/or modify
4+
# under the same terms as Python, so long as this copyright message and
5+
# disclaimer are retained in their original form.
6+
#
7+
# This module is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10+
#
11+
# $Id: test_htmltemplate.py,v 1.1 2002-01-21 11:05:48 richard Exp $
12+
13+
import unittest, cgi
14+
15+
from roundup.htmltemplate import TemplateFunctions
16+
from roundup import date
17+
from roundup.hyperdb import String, Date, Interval, Link, Multilink
18+
19+
class Class:
20+
def get(self, nodeid, attribute, default=None):
21+
if attribute == 'string':
22+
return 'Node %s: I am a string'%nodeid
23+
elif attribute == 'date':
24+
return date.Date('2000-01-01')
25+
elif attribute == 'interval':
26+
return date.Interval('-3d')
27+
elif attribute == 'link':
28+
return '1'
29+
elif attribute == 'multilink':
30+
return ['1', '2']
31+
elif attribute == 'key':
32+
return 'the key'
33+
elif attribute == 'html':
34+
return '<html>hello, I am HTML</html>'
35+
def list(self):
36+
return ['1', '2']
37+
def getprops(self):
38+
return {'string': String(), 'date': Date(), 'interval': Interval(),
39+
'link': Link('other'), 'multilink': Multilink('other'),
40+
'html': String(), 'key': String()}
41+
def labelprop(self):
42+
return 'key'
43+
44+
class Database:
45+
classes = {'other': Class()}
46+
def getclass(self, name):
47+
return Class()
48+
def __getattr(self, name):
49+
return Class()
50+
51+
class NodeCase(unittest.TestCase):
52+
def setUp(self):
53+
''' Set up the harness for calling the individual tests
54+
'''
55+
self.tf = tf = TemplateFunctions()
56+
tf.nodeid = '1'
57+
tf.cl = Class()
58+
tf.properties = tf.cl.getprops()
59+
tf.db = Database()
60+
61+
# def do_plain(self, property, escape=0):
62+
def testPlain_string(self):
63+
s = 'Node 1: I am a string'
64+
self.assertEqual(self.tf.do_plain('string'), s)
65+
66+
def testPlain_html(self):
67+
s = '<html>hello, I am HTML</html>'
68+
self.assertEqual(self.tf.do_plain('html', escape=0), s)
69+
s = cgi.escape(s)
70+
self.assertEqual(self.tf.do_plain('html', escape=1), s)
71+
72+
def testPlain_date(self):
73+
self.assertEqual(self.tf.do_plain('date'), '2000-01-01.00:00:00')
74+
75+
def testPlain_interval(self):
76+
self.assertEqual(self.tf.do_plain('interval'), '- 3d')
77+
78+
def testPlain_link(self):
79+
self.assertEqual(self.tf.do_plain('link'), 'the key')
80+
81+
def testPlain_multilink(self):
82+
self.assertEqual(self.tf.do_plain('multilink'), '1, 2')
83+
84+
85+
# def do_field(self, property, size=None, height=None, showid=0):
86+
def testField_string(self):
87+
self.assertEqual(self.tf.do_field('string'),
88+
'<input name="string" value="Node 1: I am a string" size="30">')
89+
90+
def testField_html(self):
91+
self.assertEqual(self.tf.do_field('html'), '<input name="html" '
92+
'value="&lt;html&gt;hello, I am HTML&lt;/html&gt;" size="30">')
93+
94+
def testField_date(self):
95+
self.assertEqual(self.tf.do_field('date'),
96+
'<input name="date" value="2000-01-01.00:00:00" size="30">')
97+
98+
def testField_interval(self):
99+
self.assertEqual(self.tf.do_field('interval'),
100+
'<input name="interval" value="- 3d" size="30">')
101+
102+
def testField_link(self):
103+
self.assertEqual(self.tf.do_field('link'), '''<select name="link">
104+
<option value="-1">- no selection -</option>
105+
<option selected value="1">the key</option>
106+
<option value="2">the key</option>
107+
</select>''')
108+
109+
def testField_multilink(self):
110+
self.assertEqual(self.tf.do_field('multilink'),
111+
'<input name="multilink" size="10" value="the key,the key">')
112+
113+
def suite():
114+
return unittest.makeSuite(NodeCase, 'test')
115+
116+
117+
#
118+
# $Log: not supported by cvs2svn $
119+
#
120+
#
121+
# vim: set filetype=python ts=4 sw=4 et si

0 commit comments

Comments
 (0)