88# but WITHOUT ANY WARRANTY; without even the implied warranty of
99# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1010#
11- # $Id: test_htmltemplate.py,v 1.5 2002-01-23 05:10:28 richard Exp $
11+ # $Id: test_htmltemplate.py,v 1.6 2002-01-23 05:47:57 richard Exp $
1212
1313import unittest , cgi
1414
@@ -34,7 +34,7 @@ def get(self, nodeid, attribute, default=None):
3434 elif attribute == 'password' :
3535 return password .Password ('sekrit' )
3636 elif attribute == 'key' :
37- return 'the key'
37+ return 'the key' + nodeid
3838 elif attribute == 'html' :
3939 return '<html>hello, I am HTML</html>'
4040 def list (self ):
@@ -54,6 +54,9 @@ def getclass(self, name):
5454 def __getattr (self , name ):
5555 return Class ()
5656
57+ class Client :
58+ write = None
59+
5760class NodeCase (unittest .TestCase ):
5861 def setUp (self ):
5962 ''' Set up the harness for calling the individual tests
@@ -86,7 +89,7 @@ def testPlain_interval(self):
8689 self .assertEqual (self .tf .do_plain ('interval' ), '- 3d' )
8790
8891 def testPlain_link (self ):
89- self .assertEqual (self .tf .do_plain ('link' ), 'the key ' )
92+ self .assertEqual (self .tf .do_plain ('link' ), 'the key1 ' )
9093
9194 def testPlain_multilink (self ):
9295 self .assertEqual (self .tf .do_plain ('multilink' ), '1, 2' )
@@ -127,15 +130,15 @@ def testField_interval(self):
127130 def testField_link (self ):
128131 self .assertEqual (self .tf .do_field ('link' ), '''<select name="link">
129132<option value="-1">- no selection -</option>
130- <option selected value="1">the key </option>
131- <option value="2">the key </option>
133+ <option selected value="1">the key1 </option>
134+ <option value="2">the key2 </option>
132135</select>''' )
133136
134137 def testField_multilink (self ):
135138 self .assertEqual (self .tf .do_field ('multilink' ),
136- '<input name="multilink" size="30" value="the key ,the key ">' )
139+ '<input name="multilink" size="30" value="the key1 ,the key2 ">' )
137140 self .assertEqual (self .tf .do_field ('multilink' , size = 10 ),
138- '<input name="multilink" size="10" value="the key ,the key ">' )
141+ '<input name="multilink" size="10" value="the key1 ,the key2 ">' )
139142
140143# def do_menu(self, property, size=None, height=None, showid=0):
141144 def testMenu_nonlinks (self ):
@@ -148,8 +151,8 @@ def testMenu_nonlinks(self):
148151 def testMenu_link (self ):
149152 self .assertEqual (self .tf .do_menu ('link' ), '''<select name="link">
150153<option value="-1">- no selection -</option>
151- <option selected value="1">the key </option>
152- <option value="2">the key </option>
154+ <option selected value="1">the key1 </option>
155+ <option value="2">the key2 </option>
153156</select>''' )
154157 self .assertEqual (self .tf .do_menu ('link' , size = 6 ),
155158 '''<select name="link">
@@ -160,15 +163,15 @@ def testMenu_link(self):
160163 self .assertEqual (self .tf .do_menu ('link' , showid = 1 ),
161164 '''<select name="link">
162165<option value="-1">- no selection -</option>
163- <option selected value="1">other1: the key </option>
164- <option value="2">other2: the key </option>
166+ <option selected value="1">other1: the key1 </option>
167+ <option value="2">other2: the key2 </option>
165168</select>''' )
166169
167170 def testMenu_multilink (self ):
168171 self .assertEqual (self .tf .do_menu ('multilink' , height = 10 ),
169172 '''<select multiple name="multilink" size="10">
170- <option selected value="1">the key </option>
171- <option selected value="2">the key </option>
173+ <option selected value="1">the key1 </option>
174+ <option selected value="2">the key2 </option>
172175</select>''' )
173176 self .assertEqual (self .tf .do_menu ('multilink' , size = 6 , height = 10 ),
174177 '''<select multiple name="multilink" size="10">
@@ -177,8 +180,8 @@ def testMenu_multilink(self):
177180</select>''' )
178181 self .assertEqual (self .tf .do_menu ('multilink' , showid = 1 ),
179182 '''<select multiple name="multilink" size="2">
180- <option selected value="1">other1: the key </option>
181- <option selected value="2">other2: the key </option>
183+ <option selected value="1">other1: the key1 </option>
184+ <option selected value="2">other2: the key2 </option>
182185</select>''' )
183186
184187# def do_link(self, property=None, is_download=0):
@@ -204,11 +207,11 @@ def testLink_interval(self):
204207
205208 def testLink_link (self ):
206209 self .assertEqual (self .tf .do_link ('link' ),
207- '<a href="other1">the key </a>' )
210+ '<a href="other1">the key1 </a>' )
208211
209212 def testLink_multilink (self ):
210213 self .assertEqual (self .tf .do_link ('multilink' ),
211- '<a href="other1">the key </a>, <a href="other2">the key </a>' )
214+ '<a href="other1">the key1 </a>, <a href="other2">the key2 </a>' )
212215
213216# def do_count(self, property, **args):
214217 def testCount_nonlinks (self ):
@@ -260,19 +263,62 @@ def testDownload_interval(self):
260263
261264 def testDownload_link (self ):
262265 self .assertEqual (self .tf .do_download ('link' ),
263- '<a href="other1/the key ">the key </a>' )
266+ '<a href="other1/the key1 ">the key1 </a>' )
264267
265268 def testDownload_multilink (self ):
266269 self .assertEqual (self .tf .do_download ('multilink' ),
267- '<a href="other1/the key">the key</a>, '
268- '<a href="other2/the key">the key</a>' )
270+ '<a href="other1/the key1">the key1</a>, '
271+ '<a href="other2/the key2">the key2</a>' )
272+
273+ # def do_checklist(self, property, reverse=0):
274+ def testChecklink_nonlinks (self ):
275+ s = _ ('[Checklist: not a link]' )
276+ self .assertEqual (self .tf .do_checklist ('string' ), s )
277+ self .assertEqual (self .tf .do_checklist ('date' ), s )
278+ self .assertEqual (self .tf .do_checklist ('interval' ), s )
279+ self .assertEqual (self .tf .do_checklist ('password' ), s )
280+
281+ def testChecklink_link (self ):
282+ self .assertEqual (self .tf .do_checklist ('link' ),
283+ '''the key1:<input type="checkbox" checked name="link" value="the key1">
284+ the key2:<input type="checkbox" name="link" value="the key2">
285+ [unselected]:<input type="checkbox" name="link" value="-1">''' )
286+
287+ def testChecklink_multilink (self ):
288+ self .assertEqual (self .tf .do_checklist ('multilink' ),
289+ '''the key1:<input type="checkbox" checked name="multilink" value="the key1">
290+ the key2:<input type="checkbox" checked name="multilink" value="the key2">''' )
291+
292+ # def do_note(self, rows=5, cols=80):
293+ def testNote (self ):
294+ self .assertEqual (self .tf .do_note (), '<textarea name="__note" '
295+ 'wrap="hard" rows=5 cols=80></textarea>' )
296+
297+ # def do_list(self, property, reverse=0):
298+ def testList_nonlinks (self ):
299+ s = _ ('[List: not a Multilink]' )
300+ self .assertEqual (self .tf .do_list ('string' ), s )
301+ self .assertEqual (self .tf .do_list ('date' ), s )
302+ self .assertEqual (self .tf .do_list ('interval' ), s )
303+ self .assertEqual (self .tf .do_list ('password' ), s )
304+ self .assertEqual (self .tf .do_list ('link' ), s )
305+
306+ def testList_multilink (self ):
307+ # TODO: test this (needs to have lots and lots of support!
308+ #self.assertEqual(self.tf.do_list('multilink'),'')
309+ pass
269310
270311def suite ():
271312 return unittest .makeSuite (NodeCase , 'test' )
272313
273314
274315#
275316# $Log: not supported by cvs2svn $
317+ # Revision 1.5 2002/01/23 05:10:28 richard
318+ # More HTML template cleanup and unit tests.
319+ # - download() now implemented correctly, replacing link(is_download=1) [fixed in the
320+ # templates, but link(is_download=1) will still work for existing templates]
321+ #
276322# Revision 1.4 2002/01/22 22:46:22 richard
277323# more htmltemplate cleanups and unit tests
278324#
0 commit comments