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.2 2002-01-22 00:12:07 richard Exp $
11+ # $Id: test_htmltemplate.py,v 1.3 2002-01-22 06:35:40 richard Exp $
1212
1313import unittest , cgi
1414
15+ from roundup import date , password
1516from roundup .htmltemplate import TemplateFunctions
16- from roundup import date
17- from roundup import password
17+ from roundup .i18n import _
1818from roundup .hyperdb import String , Password , Date , Interval , Link , Multilink
1919
2020class Class :
2121 def get (self , nodeid , attribute , default = None ):
2222 if attribute == 'string' :
2323 return 'Node %s: I am a string' % nodeid
24+ elif attribute == 'filename' :
25+ return 'file.foo'
2426 elif attribute == 'date' :
2527 return date .Date ('2000-01-01' )
2628 elif attribute == 'interval' :
@@ -40,7 +42,8 @@ def list(self):
4042 def getprops (self ):
4143 return {'string' : String (), 'date' : Date (), 'interval' : Interval (),
4244 'link' : Link ('other' ), 'multilink' : Multilink ('other' ),
43- 'password' : Password (), 'html' : String (), 'key' : String ()}
45+ 'password' : Password (), 'html' : String (), 'key' : String (),
46+ 'novalue' : String (), 'filename' : String ()}
4447 def labelprop (self ):
4548 return 'key'
4649
@@ -58,6 +61,7 @@ def setUp(self):
5861 self .tf = tf = TemplateFunctions ()
5962 tf .nodeid = '1'
6063 tf .cl = Class ()
64+ tf .classname = 'test_class'
6165 tf .properties = tf .cl .getprops ()
6266 tf .db = Database ()
6367
@@ -134,6 +138,12 @@ def testField_multilink(self):
134138 '<input name="multilink" size="10" value="the key,the key">' )
135139
136140# def do_menu(self, property, size=None, height=None, showid=0):
141+ def testMenu_nonlinks (self ):
142+ self .assertEqual (self .tf .do_menu ('string' ), _ ('[Menu: not a link]' ))
143+ self .assertEqual (self .tf .do_menu ('date' ), _ ('[Menu: not a link]' ))
144+ self .assertEqual (self .tf .do_menu ('interval' ), _ ('[Menu: not a link]' ))
145+ self .assertEqual (self .tf .do_menu ('password' ), _ ('[Menu: not a link]' ))
146+
137147 def testMenu_link (self ):
138148 self .assertEqual (self .tf .do_menu ('link' ), '''<select name="link">
139149<option value="-1">- no selection -</option>
@@ -170,12 +180,45 @@ def testMenu_multilink(self):
170180<option selected value="2">other2: the key</option>
171181</select>''' )
172182
183+ # def do_link(self, property=None, is_download=0):
184+ def testLink_novalue (self ):
185+ self .assertEqual (self .tf .do_link ('novalue' ),
186+ _ ('[no %(propname)s]' )% {'propname' :'novalue' .capitalize ()})
187+
188+ def testLink_string (self ):
189+ self .assertEqual (self .tf .do_link ('string' ),
190+ '<a href="test_class1">Node 1: I am a string</a>' )
191+
192+ def testLink_file (self ):
193+ self .assertEqual (self .tf .do_link ('filename' , is_download = 1 ),
194+ '<a href="test_class1/file.foo">file.foo</a>' )
195+
196+ def testLink_date (self ):
197+ self .assertEqual (self .tf .do_link ('date' ),
198+ '<a href="test_class1">2000-01-01.00:00:00</a>' )
199+
200+ def testLink_interval (self ):
201+ self .assertEqual (self .tf .do_link ('interval' ),
202+ '<a href="test_class1">- 3d</a>' )
203+
204+ def testLink_link (self ):
205+ self .assertEqual (self .tf .do_link ('link' ),
206+ '<a href="other1">the key</a>' )
207+
208+ def testLink_multilink (self ):
209+ self .assertEqual (self .tf .do_link ('multilink' ),
210+ '<a href="other1">the key</a>, <a href="other2">the key</a>' )
211+
173212def suite ():
174213 return unittest .makeSuite (NodeCase , 'test' )
175214
176215
177216#
178217# $Log: not supported by cvs2svn $
218+ # Revision 1.2 2002/01/22 00:12:07 richard
219+ # Wrote more unit tests for htmltemplate, and while I was at it, I polished
220+ # off the implementation of some of the functions so they behave sanely.
221+ #
179222# Revision 1.1 2002/01/21 11:05:48 richard
180223# New tests for htmltemplate (well, it's a beginning)
181224#
0 commit comments