Skip to content

Commit 8dea923

Browse files
author
Richard Jones
committed
more htmltemplate cleanups and unit tests
1 parent 5a00386 commit 8dea923

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

roundup/htmltemplate.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: htmltemplate.py,v 1.66 2002-01-22 06:35:40 richard Exp $
18+
# $Id: htmltemplate.py,v 1.67 2002-01-22 22:46:22 richard Exp $
1919

2020
__doc__ = """
2121
Template engine.
@@ -302,8 +302,8 @@ def do_link(self, property=None, is_download=0):
302302

303303
# get the value
304304
value = self.determine_value(property)
305-
if not value:
306-
return _('[no %(propname)s]')%{'propname':property.capitalize()}
305+
if not value:
306+
return _('[no %(propname)s]')%{'propname':property.capitalize()}
307307

308308
propclass = self.properties[property]
309309
if isinstance(propclass, hyperdb.Link):
@@ -342,11 +342,14 @@ def do_count(self, property, **args):
342342
'''
343343
if not self.nodeid:
344344
return _('[Count: not called from item]')
345+
345346
propclass = self.properties[property]
347+
if not isinstance(propclass, hyperdb.Multilink):
348+
return _('[Count: not a Multilink]')
349+
350+
# figure the length then...
346351
value = self.cl.get(self.nodeid, property)
347-
if isinstance(propclass, hyperdb.Multilink):
348-
return str(len(value))
349-
return _('[Count: not a Multilink]')
352+
return str(len(value))
350353

351354
# XXX pretty is definitely new ;)
352355
def do_reldate(self, property, pretty=0):
@@ -357,13 +360,19 @@ def do_reldate(self, property, pretty=0):
357360
'''
358361
if not self.nodeid and self.form is None:
359362
return _('[Reldate: not called from item]')
363+
360364
propclass = self.properties[property]
361-
if isinstance(not propclass, hyperdb.Date):
365+
if not isinstance(propclass, hyperdb.Date):
362366
return _('[Reldate: not a Date]')
367+
363368
if self.nodeid:
364369
value = self.cl.get(self.nodeid, property)
365370
else:
366-
value = date.Date('.')
371+
return ''
372+
if not value:
373+
return ''
374+
375+
# figure the interval
367376
interval = value - date.Date('.')
368377
if pretty:
369378
if not self.nodeid:
@@ -1038,6 +1047,9 @@ def render(self, form):
10381047

10391048
#
10401049
# $Log: not supported by cvs2svn $
1050+
# Revision 1.66 2002/01/22 06:35:40 richard
1051+
# more htmltemplate tests and cleanup
1052+
#
10411053
# Revision 1.65 2002/01/22 00:12:06 richard
10421054
# Wrote more unit tests for htmltemplate, and while I was at it, I polished
10431055
# off the implementation of some of the functions so they behave sanely.

test/test_htmltemplate.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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.3 2002-01-22 06:35:40 richard Exp $
11+
# $Id: test_htmltemplate.py,v 1.4 2002-01-22 22:46:22 richard Exp $
1212

1313
import unittest, cgi
1414

@@ -183,7 +183,7 @@ def testMenu_multilink(self):
183183
# def do_link(self, property=None, is_download=0):
184184
def testLink_novalue(self):
185185
self.assertEqual(self.tf.do_link('novalue'),
186-
_('[no %(propname)s]')%{'propname':'novalue'.capitalize()})
186+
_('[no %(propname)s]')%{'propname':'novalue'.capitalize()})
187187

188188
def testLink_string(self):
189189
self.assertEqual(self.tf.do_link('string'),
@@ -209,12 +209,41 @@ def testLink_multilink(self):
209209
self.assertEqual(self.tf.do_link('multilink'),
210210
'<a href="other1">the key</a>, <a href="other2">the key</a>')
211211

212+
# def do_count(self, property, **args):
213+
def testCount_nonlinks(self):
214+
s = _('[Count: not a Multilink]')
215+
self.assertEqual(self.tf.do_count('string'), s)
216+
self.assertEqual(self.tf.do_count('date'), s)
217+
self.assertEqual(self.tf.do_count('interval'), s)
218+
self.assertEqual(self.tf.do_count('password'), s)
219+
self.assertEqual(self.tf.do_count('link'), s)
220+
221+
def testCount_multilink(self):
222+
self.assertEqual(self.tf.do_count('multilink'), '2')
223+
224+
# def do_reldate(self, property, pretty=0):
225+
def testReldate_nondate(self):
226+
s = _('[Reldate: not a Date]')
227+
self.assertEqual(self.tf.do_reldate('string'), s)
228+
self.assertEqual(self.tf.do_reldate('interval'), s)
229+
self.assertEqual(self.tf.do_reldate('password'), s)
230+
self.assertEqual(self.tf.do_reldate('link'), s)
231+
self.assertEqual(self.tf.do_reldate('multilink'), s)
232+
233+
def testReldate_date(self):
234+
self.assertEqual(self.tf.do_reldate('date'), '- 2y 1m')
235+
self.assertEqual(self.tf.do_reldate('date', pretty=1),
236+
' 1 January 2000')
237+
212238
def suite():
213239
return unittest.makeSuite(NodeCase, 'test')
214240

215241

216242
#
217243
# $Log: not supported by cvs2svn $
244+
# Revision 1.3 2002/01/22 06:35:40 richard
245+
# more htmltemplate tests and cleanup
246+
#
218247
# Revision 1.2 2002/01/22 00:12:07 richard
219248
# Wrote more unit tests for htmltemplate, and while I was at it, I polished
220249
# off the implementation of some of the functions so they behave sanely.

0 commit comments

Comments
 (0)